Installation
Usage
Component API
Switch
Toggle switch component built on Radix UI Switch.size- Switch size ("sm"|"default")checked- Controlled checked statedefaultChecked- Default checked stateonCheckedChange- Callback when checked state changesdisabled- Disables the switcharia-invalid- Shows error state styling
Implementation
The switch includes a thumb that animates:Examples
Basic Switch
With Label
Switch with associated label:Controlled Switch
With Description
Switch with label and description:Disabled State
Invalid State
Show validation error:Different Sizes
Settings Panel
Practical example:Form Integration
With React Hook Form:Choice Card
Clickable card-style switch:Accessibility
- Uses
role="switch"semantics - Keyboard accessible (Space to toggle)
- Proper ARIA attributes
- Focus visible states
- Associated labels via
htmlFor - Screen reader announcements