Overview
A near-imperceptible boolean control — tens of taps a day. The thumb springs across the track with bounce: 0 (~280ms). Press scales to 0.96. Under prefers-reduced-motion, the travel snaps shorter instead of vanishing.
Installation
Basic Usage
tsx
import { ToggleSwitch } from "@/components/ui/toggle-switch"; <ToggleSwitch label="Daily ops digest" checked={on} onCheckedChange={setOn}/>
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| checked | boolean | No | — | Controlled checked state. |
| defaultChecked | boolean | No | false | Uncontrolled initial state. |
| onCheckedChange | (checked: boolean) => void | No | — | Fires when the switch toggles. |
| label | string | No | — | Visible label beside the track. |
| disabled | boolean | No | — | Disables interaction. |
Best Practices
- Keep the spring short — this control fires often.
- Use
role="switch"semantics (already wired) and Space/Enter. - Prefer a visible label;
aria-labelfalls back when omitted.