Switch
Accessible on/off control for settings, preferences, and binary toggles.
Soften large animations without changing layout.
Switch is built on Radix UI, so it supports controlled and uncontrolled state, keyboard interaction, and form-friendly behavior while matching the glass-ui visual language.
Use it for settings and preference toggles where the user is turning a feature on or off. If the choice should submit as a standard checkbox in a dense form row, Checkbox is still the simpler option.
Installation
npx @glass-ui-kit/cli add switchUsage
Examples
Sizes
Use size when the toggle needs to align with denser settings rows or larger touch targets.
Disabled
Use disabled when the current state is informative but the user should not change it.
This preference is managed by your workspace admin.
Critical alerts stay enabled even when the control is locked.
Controlled
Use checked and onCheckedChange when a parent component owns the setting state.
Styling
Switch keeps the visual treatment intentionally fixed. Reach for size first, then use className for one-off layout tweaks around the baseline control.
API Reference
Accepts all Radix Switch.Root props.
| Prop | Type |
|---|---|
size | "sm" | "md" | "lg" |
checked | boolean |
defaultChecked | boolean |
onCheckedChange | (checked: boolean) => void |
disabled | boolean |
required | boolean |
name | string |
value | string |
className | string |
Pair Switch with Label using id and htmlFor for explicit associations, or compose it inside Field when you want shared label and description wiring.