Toggle switch

An on/off switch for settings that take effect immediately, such as notifications or feature flags. For a choice that is confirmed with a submit button, use a checkbox.

  • vig-toggle-switch
Import
import { ToggleSwitch } from '@vigdx/ui/toggle-switch';

Basic

Bind [(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

Where a column header already names the control, hideLabel hides the label text but keeps it as the accessible name. Include the row name so every label is unique.

Integrations
IntegrationActive
Slack

GitHub

Calendar

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel . Disabling the control disables the switch.

{
  "publicProfile": true,
  "onlineStatus": false
}

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"]

ToggleSwitch styling hooks
Part Element data-state
root The <label> wrapping switch and text. checked, unchecked
input The visually hidden role="switch" checkbox. —
track The switch track. —
thumb The sliding thumb. —
label The label text. —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The 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. label is required, also with hideLabel.
  • Hint, disabled reason and error are linked through aria-describedby; a touched, invalid switch sets aria-invalid="true". readonly reverts each change and sets aria-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 component
ToggleSwitch props
Name Type Default Description
dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
hiddenbooleanfalse
—
hideLabelbooleanfalse

Keeps the label for assistive tech only, e.g. inside a table cell or a matrix.

hintstring | undefinedundefined
—
invalidbooleanfalse
—
label required string—
—
namestring''
—
pendingbooleanfalse
—
readonlybooleanfalse
—
requiredbooleanfalse
—
touchedbooleanfalse
—
value model booleanfalse
—

VigValueAccessor

directive

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.

VigValueAccessor methods
Signature Description
registerOnChange(fn: (value: unknown) => void): void
—
registerOnTouched(fn: () => void): void
—
setDisabledState(disabled: boolean): void
—
writeValue(value: unknown): void
—

Are you sure?