Switch

Switch is used to select one or more options from a list.

Source
Theme Source
pnpm dlx dreamy add switch

Switch allows users to toggle between two states (on/off). Use it for boolean settings and preferences in forms or configuration panels.

<Switch>
	Default
</Switch>

Change the color scheme of the Switch.

<Switch scheme="primary" defaultChecked>Primary</Switch>
<Switch scheme="secondary" defaultChecked>Secondary</Switch>
<Switch scheme="success" defaultChecked>Success</Switch>
<Switch scheme="warning" defaultChecked>Warning</Switch>
<Switch scheme="error" defaultChecked>Error</Switch>
<Switch scheme="info" defaultChecked>Info</Switch>
<Switch scheme="none" defaultChecked>None</Switch>

Change the Switch size.

<Switch size="sm">Sm</Switch>
<Switch size="md">Md</Switch>
<Switch size="lg">Lg</Switch>

Use isChecked with onChange or onChangeValue to control the Switch.

Selected: false

export function ControlledSwitch() {
    const [isChecked, setIsChecked] = useState(false);
 
    return (
        <>
            <Text>Selected: {isChecked ? "true" : "false"}</Text>
            <Switch
                isChecked={isChecked}
                onChangeValue={setIsChecked}
            >
                Controlled
            </Switch>
        </>
    );
}

Switch is a compound control: a styled root label, a hidden checkbox input, a visual control track, a thumb, and an optional text label.

PropForwarded toDescription
onChangehidden inputNative checkbox change event
onChangeValuehidden inputBoolean callback when the value changes
name, value, tabIndex, autoFocushidden inputStandard form input attributes
isChecked, defaultChecked, isIndeterminatehidden inputChecked state
isDisabled, isReadOnly, isRequired, isInvalidroot + hidden inputField state
inputPropshidden inputExtra props for the hidden checkbox
wrapperPropscontrol spanProps for the visual track
labelPropslabel spanProps for the text label
thumbPropsthumbProps for the animated thumb
scheme, sizerootRecipe variants
other HTML/data-* propsrootApplied to the root label

Use top-level props such as name and onChange for the common case. Reach for inputProps, wrapperProps, labelProps, and thumbProps when you need to target a specific internal element.

<Switch
    name="notifications"
    defaultChecked
    inputProps={{ "aria-label": "Email notifications" }}
    wrapperProps={{ "data-testid": "switch-control" }}
    labelProps={{ className: "font-medium" }}
>
    Email notifications
</Switch>