Toggle switch
vig-toggle-switch
import { ToggleSwitch } from '@vigdx/ui/toggle-switch';Basic
[(value)] to a boolean signal. The label follows the switch and hint adds help text. Under right-to-left the track and thumb mirror; try the RTL switch below.
Visitors see a static page while this is on.
Notifications are on; maintenance mode is off.
States
disabled greys the switch out. readonly keeps it focusable but ignores clicks and Space; explain why in the hint .
Your administrator controls this setting.
Hidden label
hideLabel hides the label text but keeps it as the accessible name. Include the row name so every label is unique.
| Integration | Active |
|---|---|
| Slack | |
| GitHub | |
| Calendar |
Reactive Forms
VigValueAccessor next to the component to use formControlName , [formControl] or ngModel . Disabling the control disables the switch.
Signal Forms
vig-toggle-switch implements FormValueControl<boolean> . A disabled() rule that returns a string disables the switch and shows the string as the reason.
Backups: on · Encryption: off
Styling hooks
Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="toggle-switch"][data-part="root"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.
Scope: [data-scope="toggle-switch"]
| Part | Element | data-state |
|---|---|---|
root | <label> wrapping switch and text. | checked, unchecked |
input | role="switch" checkbox. | — |
track | — | |
thumb | — | |
label | — | |
hint | vig-hint (a display: contents host; style its text part). | — |
disabled-reason | vig-hint with the disabled reason ( display: contents ). | — |
error | vig-field-error (a display: contents host; style its message part). | — |
Accessibility
- A native checkbox with
role="switch", so screen readers announce it as a switch that is on or off; Space toggles it. - The input sits inside its
<label>, so the label text is the accessible name and clicking it toggles the switch.labelis required, also withhideLabel. - Hint, disabled reason and error are linked through
aria-describedby; a touched, invalid switch setsaria-invalid="true".readonlyreverts each change and setsaria-readonly="true". - The track shows a focus ring on keyboard focus, and the thumb animation is turned off under
prefers-reduced-motion. - Changes apply at once, so do not hide them behind a save button; announce the result if it is not visible next to the switch.
API
ToggleSwitch
vig-toggle-switch| Name | Type | Default | Description |
|---|---|---|---|
dirty | boolean | false | — |
disabled | boolean | false | — |
disabledReasons | readonly WithOptionalFieldTree<DisabledReason>[] | [] | — |
errorMessages | Record<string, string> | — | — |
errors | readonly ValidationError.WithOptionalFieldTree[] | [] | — |
hidden | boolean | false | — |
hideLabel | boolean | false | Keeps the label for assistive tech only, e.g. inside a table cell or a matrix. |
hint | string | undefined | undefined | — |
invalid | boolean | false | — |
label | string | — | — |
name | string | '' | — |
pending | boolean | false | — |
readonly | boolean | false | — |
required | boolean | false | — |
touched | boolean | false | — |
value | boolean | false | — |
| Name | Payload | Description |
|---|---|---|
touch | void | — |
valueChange | boolean | — |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void | Moves focus to the control's interactive element (the input, or the
trigger of a popup control). Signal Forms calls it through
|
reset(): void | Returns the control to its pristine look: drops in-progress text, closes
an open popup, clears errors the component raised itself and the
submitted state of |
VigValueAccessor
Bridges the vigdx form fields to Reactive Forms (formControl,
formControlName) and template-driven forms (ngModel). Import it next to
the component; Signal Forms ([formField]) need no accessor.
| Signature | Description |
|---|---|
registerOnChange(fn: (value: unknown) => void): void | — |
registerOnTouched(fn: () => void): void | — |
setDisabledState(disabled: boolean): void | — |
writeValue(value: unknown): void | — |