Switch
A control that allows the user to toggle between on and off states.
Examples
Regular
Preview
Disabled
Preview
With Custom Icons
Preview
With Description
Preview
API
Switch
| Property | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | false | Change the default rendered element for the one passed as a child, merging their props and behavior. |
| defaultChecked | boolean | - | The state of the switch when it is initially rendered. Use when you do not need to control its state. |
| checked | boolean | - | The controlled state of the switch. Must be used in conjunction with onCheckedChange. |
| onCheckedChange | (checked: boolean) => void | - | Event handler called when the state of the switch changes. |
| disabled | boolean | - | When true, prevents the user from interacting with the switch. |
| required | boolean | - | When true, indicates that the user must check the switch before the owning form can be submitted. |
| name | string | - | The name of the switch. Submitted with its owning form as part of a name/value pair. |
| value | string | ”on” | The value given as data when submitted with a name. |
| variant | ”regular" | "regular” | The visual style of the switch. |
| size | ”sm” | “md” | “lg" | "md” | The size of the switch. |
| checkedIcon | React.ReactNode | - | Custom icon to display when the switch is checked. |
| uncheckedIcon | React.ReactNode | - | Custom icon to display when the switch is unchecked. |
| Data attribute | Values |
|---|---|
| [data-state] | “checked” | “unchecked” |
| [data-disabled] | Present when disabled |
Last updated on