View fulldotdev/ui on GitHub

Switch

A control that allows the user to toggle between checked and not checked.

Installation

npx shadcn@latest add @fulldev/switch

Usage

import { Switch } from "@/components/ui/switch"
<Switch id="notifications" name="notifications" />

Switch renders a span with role="switch" and injects a visually hidden checkbox for form submission. Label it with a Label whose for matches the switch id, or wrap it in a label.

Description

Choice Card

Card-style selection where FieldLabel wraps the entire Field for a clickable card pattern.

Disabled

Add disabled to the Switch and data-disabled to the Field for styling.

Invalid

Add aria-invalid="true" to the Switch and data-invalid to the Field for styling.

Size

Use the size prop to change the size of the switch.

RTL

Set dir="rtl" on the field or a parent element.

API Reference

Source: src/components/ui/switch

PropTypeDefault
defaultCheckedbooleanfalse
disabledbooleanfalse
readOnlybooleanfalse
requiredbooleanfalse
namestring
valuestring"on"
uncheckedValuestring
size"default" | "sm""default"

See the data-slot docs for events such as switch:change.