Switch
Switch
A control that allows the user to toggle between checked and not checked.
Usage
Switch Props
Prop | Type | Default |
---|---|---|
checked | boolean | - |
defaultChecked | boolean | - |
onCheckedChange | ((checked: boolean) => void) | - |
disabled | boolean | - |
required | boolean | - |
size | "large" | "small" | "large" |
id | string | - |
Examples
State
The Switch component supports various states to handle different interaction scenarios.
Size Variants
The Switch component comes in two sizes: large (default) and small.
Controlled Usage
Use the Switch component in a controlled manner to manage its state externally.
Accessibility
The Switch component follows WAI-ARIA guidelines for toggle buttons:
- Uses proper ARIA attributes (
aria-checked
,aria-required
,aria-label
) - Supports keyboard navigation (Space and Enter to toggle)
- Includes proper labeling and description support
- Changes cursor to 'not-allowed' when disabled
- Associates labels with the switch using htmlFor