Switch

A toggle switch for boolean values, rendered as an accessible button with role="switch".

Installation

npx dafink-ui add switch

Demo

Receive updates about your account.

Props

NameTypeDefaultDescription
checkedboolean-Controlled checked state.
onCheckedChange(checked: boolean) => void-Callback fired when the switch is toggled.
labelstring-Visible label rendered beside the switch.
hintstring-Helper text rendered below the label.
disabledbooleanfalseDisables the switch.
idstringautoHTML id for the switch button; auto-derived from label if omitted.

Accessibility

Switch renders a native <button role="switch"> with aria-checked mirroring the controlled checked prop: no custom keyboard handling, Enter/Space toggle it via native button semantics, and it sits in normal Tab order as a single stop, no roving tabindex or arrow keys. label is linked via htmlFor/id, and hint is linked via aria-describedby.