Switch
FormsA toggle switch for binary on/off choices. Use switches for settings that take effect immediately without requiring a form submission.
Import
import { Switch } from "@/components/ui/switch";Usage
Basic Switch
Standard toggle switch
Controlled Switch
Switch with controlled state
Settings Example
Common settings toggle patterns
Disabled States
Switches in disabled state
API Reference
label—stringLabel text displayed next to the switch
checked—booleanControlled checked state
defaultCheckedfalsebooleanInitial checked state (uncontrolled)
disabledfalsebooleanWhether the switch is disabled
onChange—(e: ChangeEvent) => voidHandler called when state changes
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Label text displayed next to the switch |
checked | boolean | — | Controlled checked state |
defaultChecked | boolean | false | Initial checked state (uncontrolled) |
disabled | boolean | false | Whether the switch is disabled |
onChange | (e: ChangeEvent) => void | — | Handler called when state changes |