Switch
A toggle for a single on/off setting. Built on base-ui Switch — keyboard support, focus management, and ARIA wiring come for free.
Reach for a Switch when flipping it takes effect immediately (a preference, a feature toggle) — “Email me tracking updates”, “Require signature”. Use a Checkbox instead when the choice is part of a form the user submits, or when it sits in a list of selectable options. One rule of thumb: a switch is a setting, a checkbox is a selection.
Basic
Pair a Switch with a Label — match the label’s htmlFor to the switch’s id so clicking the text also flips it. It’s uncontrolled by default.
Default on
Pass defaultChecked to start in the on position while leaving the switch uncontrolled.
Disabled
disabled blocks interaction and dims the track. It works in either state — use a forced-on disabled switch to show a setting that’s locked on (e.g. granted by a higher-level permission).
Controlled
Drive the switch yourself with checked plus onCheckedChange — the handler receives the next boolean directly, no event unwrapping.
Labels are bought manually.
Settings list
The common pattern: a FieldGroup of horizontal Field rows, each with a FieldContent (title + description) on the left and a Switch on the right. Give each switch an aria-label so it’s named for screen readers.
Get a message each time a shipment changes status.
Carriers will collect a signature before releasing the package.
Purchase the cheapest qualifying rate as soon as an order is marked fulfilled.
Reference
Switch
Extends base-ui Switch.Root props (minus onChange).
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Checked state (controlled) |
defaultChecked | boolean | false | Initial checked state (uncontrolled) |
onCheckedChange | (checked: boolean) => void | — | Fires with the next checked state on toggle |
disabled | boolean | false | Blocks interaction and dims the track |
size | "sm" | "md" | "md" | Track and thumb size; sm for dense rows |
className | string | — | Merged onto the root |