Switch
A toggle control that allows users to turn a setting on or off, with support for labels, validation states, and loading states.
Import
Usage
Examples
Default checked
Controlled
Checked: false
With label
With description
Receive email updates about your account
Inheritance
Switch extends the <Input/> component and inherits all of its layout and field props and functionality. This means you can use any Input prop with Switch, including:
size,color,radiuslabel,labelAlign,description,messagestatus,required,isLoading,disabledclassName, and all native input attributes
Reference: For a complete list of inherited props with detailed descriptions, see the Input documentation.
What Switch adds
| Feature | Description |
|---|---|
| Toggle State | Controlled (checked) and uncontrolled (defaultChecked) toggle states |
| Toggle Callback | Custom onChange receiving the boolean checked state and change event |
| Track & Thumb Layout | Custom toggle track and sliding thumb structure |
What Switch modifies
| Modification | Description |
|---|---|
radius | Defaults to "full" to render a pill-shaped track |
onChange | Receives (checked: boolean, event: ChangeEvent<HTMLInputElement>) instead of standard input value changes |
What Switch does not inherit
The following Input props are not available on Switch:
| Prop | Reason |
|---|---|
variant | Not applicable - Switch uses a custom track layout instead of text input variants |
startContent / endContent | Not applicable - content slots are replaced by the switch track and thumb |
type | Not applicable - Switch is fixed to a checkbox with role="switch" |
value / defaultValue | Replaced with checked / defaultChecked |
All other Input props are fully supported. See the Input documentation for the complete list.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | None | Controlled checked state |
defaultChecked | boolean | false | Default checked state for uncontrolled usage |
onChange | (checked: boolean, event: ChangeEvent<HTMLInputElement>) => void | None | Callback when toggled |
Global Configuration
Switch reads defaults from four places, in this order of precedence:
- Instance prop: set directly on
<Switch/> - Component config:
components.switchin yourashee.config - Theme default:
defaultColor/defaultRadiusin yourashee.config - Built-in fallback: component's internal default values
Component config
Built-in fallbacks
Accessibility
- Renders a native
<input type="checkbox">withrole="switch" - Uses
aria-checkedto indicate state - Uses
aria-invalidfor error states - Uses
aria-busyfor loading state - Uses
aria-disabledfor disabled state - Implements
focus-visiblerings for keyboard navigation - Labels are properly associated with the switch via
htmlFor/id - Supports keyboard interaction with Space and Enter keys
Notes
- Controlled vs Uncontrolled: Use
checked/onChangefor controlled usage, ordefaultCheckedfor uncontrolled. - Status Colors: When
statusis set toerror,success, orwarning, the switch border reflects the status color. - Loading State: When
isLoadingistrue, the switch is disabled and shows reduced opacity. - Color: The switch uses the
colorprop for the checked state background color. - Radius: The
fullradius creates a pill-shaped switch, which is the default behavior. - Field Shell Integration: Switch integrates with
FieldShellto provide consistent layout handling for labels, descriptions, and validation messages.