Switch
stableA control that allows the user to toggle between checked and not checked.
Basic usage
Examples
Controlled toggle
Track the checked state externally to drive other UI.
Status: disabled
Settings list
Use controlled or uncontrolled switches inside dense settings panels.
Release preferences
Realistic app composition
Semantic colors
Switch accepts a color prop to match the semantic context of the toggle.
Features
- Full keyboard navigation.
- Can be controlled or uncontrolled.
- iOS-style spring thumb animation.
Installation
bash
pnpm dlx structyl add switchAPI Reference
Switch
A toggle control with role="switch".
| Prop | Type | Default |
|---|---|---|
| checked | booleanControlled checked state. | — |
| defaultChecked | booleanInitial checked state when uncontrolled. | — |
| onCheckedChange | (checked: boolean) => voidCalled when the checked state changes. | — |
| disabled | booleanDisable the switch. | false |
| required | booleanMark as required in a form. | false |
| name | stringName for form submission. | — |
| size | 'sm' | 'md' | 'lg'Visual size. | 'md' |
| className | stringAdditional Tailwind classes, merged with the component defaults. | — |
Keyboard interactions
Adheres to the WAI-ARIA design pattern .
| Key | Description |
|---|---|
| Space / Enter | Toggles the switch. |