ArtificialSenseDocs

Docs / Components

SenseToggleSwitchComponent

Accessible on/off switch from @artificialsenselabs/ui with label, keyboard support, and forms integration.

Live demo: run nx serve showcase and open /components/toggle-switch (port 4202).

Overview

Category: Form control. Selector: sense-toggle-switch. Import: import { SenseToggleSwitchComponent } from '@artificialsenselabs/ui';

<sense-toggle-switch
  label="Notifications"
  [(ngModel)]="enabled"
  (switchChange)="onSwitchChange($event)"
/>

Listen to switchChange for the full event payload โ€” not checkedChange from the model() alone.

Inputs & outputs

MemberTypeDefaultDescription
labelstring | nullnullVisible label; omit when using ariaLabel alone.
ariaLabelstring | nullnullAccessible name when no visible label.
checkedbooleanfalseTwo-way model for on/off state.
size'sm' | 'md' | 'lg''md'Visual density preset.
readonlybooleanfalsePrevents toggling while keeping the control focusable.
switchChangeSenseToggleSwitchChangeEventโ€”Emits { checked, originalEvent } on user toggle.

Accessibility

  • Native checkbox with role="switch" per the ARIA switch pattern.
  • Visible labels use aria-labelledby; icon-only uses aria-label.
  • Space key toggles when focused; decorative track is aria-hidden.
  • Implements ControlValueAccessor for Angular forms integration.