Import
Anatomy
The Switch component consists of two parts:Switch.Root- The switch control itselfSwitch.Thumb- The draggable thumb element
Basic Usage
Key Features
- Controlled and uncontrolled modes
- Accessible with proper ARIA attributes
- Works seamlessly with Field and Form components
- Custom render props
- Support for read-only and disabled states
Key Props
checked
Type:boolean
Whether the switch is currently active. Use with onCheckedChange for controlled mode.
defaultChecked
Type:boolean
Default: false
Whether the switch is initially active. Use for uncontrolled mode.
onCheckedChange
Type:(checked: boolean, eventDetails: ChangeEventDetails) => void
Event handler called when the switch is activated or deactivated.
disabled
Type:boolean
Default: false
Whether the component should ignore user interaction.
readOnly
Type:boolean
Default: false
Whether the user should be unable to activate or deactivate the switch.
required
Type:boolean
Default: false
Whether the user must activate the switch before submitting a form.
name
Type:string
Identifies the field when a form is submitted.
value
Type:string
The value submitted with the form when the switch is on.
uncheckedValue
Type:string
The value submitted with the form when the switch is off.
inputRef
Type:React.Ref<HTMLInputElement>
A ref to access the hidden input element.
Styling
- Tab Title
- Tab Title