Switch

A control that allows the user to toggle between checked and not checked.

Installation

ng g @spartan-ng/cli:ui switch

Usage

import { HlmSwitch } from '@spartan-ng/helm/switch';
<hlm-switch />

Examples

Description

Focus is shared across devices, and turns off when you leave the app.

Choice Card

Disabled

Invalid

You must accept the terms and conditions to continue.

Sizes

RTL

To enable RTL support in spartan-ng, see the RTL configuration guide.

يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.

Brain API

BrnSwitchThumb

Selector: [brnSwitchThumb],brn-switch-thumb

BrnSwitch

Selector: brn-switch

Inputs

PropTypeDefaultDescription
checked boolean false Whether switch is checked/toggled on. Can be bound with [(checked)] for two-way binding.
id string | null ++uniqueIdCounter + '' Unique identifier for switch component. When provided, inner button gets ID without '-switch' suffix. Auto-generates ID if not provided.
name string | null null Form control name for switch. When provided, inner button gets name without '-switch' suffix.
class string | null null CSS classes applied to inner button element.
hostStyles string 'display: contents' Styles applied to the host element. Bound via `[style]` so they apply through the CSSOM and are not blocked by a strict Content-Security-Policy.
size BrnSwitchSize 'default' Size of the switch. Drives the size-keyed registry style rules via the `data-size` attribute.
forceInvalid boolean false Whether to force the input into an invalid state.
aria-label string | null null Accessibility label for screen readers. Use when no visible label exists.
aria-labelledby string | null null ID of element that labels this switch for accessibility. Auto-set when switch is inside label element.
aria-describedby string | null null ID of element that describes this switch for accessibility.
required boolean false Whether switch is required in a form.
disabled boolean false Whether switch is disabled. Disabled switches cannot be toggled and indicate disabled state with data attribute.
tabIndex number 0 Keyboard tab order for switch.

Outputs

PropTypeDefaultDescription
checkedChange boolean - Emits when checked state changes.
touched void - Event emitted when switch is blurred (loses focus). Used for form validation.

Helm API

HlmSwitchThumb

Selector: [hlmSwitchThumb],hlm-switch-thumb

HlmSwitch

Selector: hlm-switch

Inputs

PropTypeDefaultDescription
class ClassValue '' -
checked boolean false The checked state of the switch.
disabled boolean false The disabled state of the switch.
size BrnSwitchSize 'default' The size of the switch.
inputId string | null null Used to set the id on the underlying brn element.
forceInvalid boolean false Whether to force the input into an invalid state.
aria-label string | null null Used to set the aria-label attribute on the underlying brn element.
aria-labelledby string | null null Used to set the aria-labelledby attribute on the underlying brn element.
aria-describedby string | null null Used to set the aria-describedby attribute on the underlying brn element.

Outputs

PropTypeDefaultDescription
checkedChange boolean - Emits when the checked state of the switch changes.
Table Spinner