An on/off toggle (a native checkbox with role="switch") with a label and optional helper text or error.
A Markdown brief for Claude, Cursor or v0: install, setup, props and a complete example.
For a setting that takes effect the moment it flips, like notifications.
Part of a form that’s saved with a button? Checkbox.
role="switch" with its state announced as on or off. Space toggles it.
import { Switch } from '@idyeah/diya'Stable since 1.0.0
labelRequiredstringVisible label beside the switch; also its accessible name. Hide it with hideLabel.
checkedbooleanWhether the switch is on, when controlled; pair it with onCheckedChange.
defaultCheckedbooleanWhether the switch starts on when uncontrolled; a form reset returns to it.
disabledbooleanPrevents toggling and dims the switch.
Default false
errorstringVisible error message below the label; marks the switch invalid while set.
helperTextstringVisible hint below the label, announced with the switch; error replaces it while set.
hideLabelbooleanHides the label visually but keeps it as the switch's accessible name.
Default false
onCheckedChange(checked: boolean) => voidCalled with the new on/off state when the switch is toggled.
size"small" | "medium" | "large"Track and thumb size; defaults to 'medium'.
Default 'medium'
valuestringThe value sent with the form under name while the switch is on; defaults to "on", like a checkbox.
Also takes every native <input> attribute, such as name, id or data-*.