Skip to Content
DocumentationSwitch

Switch

A control that allows the user to toggle between on and off states.

Examples

Regular

Disabled

With Custom Icons

With Description

API

Switch

PropertyTypeDefaultDescription
asChildbooleanfalseChange the default rendered element for the one passed as a child, merging their props and behavior.
defaultCheckedboolean-The state of the switch when it is initially rendered. Use when you do not need to control its state.
checkedboolean-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.
disabledboolean-When true, prevents the user from interacting with the switch.
requiredboolean-When true, indicates that the user must check the switch before the owning form can be submitted.
namestring-The name of the switch. Submitted with its owning form as part of a name/value pair.
valuestring”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.
checkedIconReact.ReactNode-Custom icon to display when the switch is checked.
uncheckedIconReact.ReactNode-Custom icon to display when the switch is unchecked.
Data attributeValues
[data-state]“checked” | “unchecked”
[data-disabled]Present when disabled
Last updated on