Switch
A control that allows the user to toggle between checked and not checked.
Usage
The Switch component provides a toggleable control with support for controlled and disabled states.
Switch Props
Prop | Type | Default |
---|---|---|
checked | boolean | - |
defaultChecked | boolean | - |
onCheckedChange | (checked: boolean) => void | - |
disabled | boolean | - |
required | boolean | - |
id | string | - |
Examples
State
The Switch component supports various states to handle different interaction scenarios.
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