Components
- Accordion
- Action Bar
- Alert Dialog
- Alert
- Announcement
- Aspect Ratio
- Autocomplete
- Avatar
- Badge
- Bottom Navigation
- Breadcrumb
- Button Group
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Circular Progress
- Circular Slider
- Clipboard
- Collapsible
- Color Picker
- Combobox
- Command
- Context Menu
- Data List
- Date Picker
- Dialog
- Drawer
- Editable
- Field
- File Upload
- Float
- Floating Panel
- Frame
- Hint
- Hover Card
- Image Cropper
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Link Overlay
- Listbox
- Marquee
- Menu
- Native Select
- Number Input
- Pagination
- Popover
- Progress
- Prose
- QR Code
- Radio Group
- Rating
- Resizable
- Scroll Area
- Segment Group
- Select
- Separator
- Sheet
- Sidebar
- Signature Pad
- Skeleton
- Skip Nav
- Slider
- Spinner
- Status
- Steps
- Switch
- Table
- Tabs
- Textarea
- Timer
- Toast
- Toggle Group
- Toggle Tooltip
- Toggle
- Tooltip
- Tour
- Tree View
Installation
pnpm dlx shadcn@latest add https://shark.vini.one/r/switch.json
Usage
import { Switch } from "@/components/ui/switch";
<Switch />
Controlled
Use the checked and onCheckedChange props to control the switch state programmatically.
❌
State
Invalid
Use the invalid prop on the <Field /> or in the <Switch /> component to mark the switch as invalid.
Examples
Disabled
Use the disabled prop to disable the switch.
With Description
Use <FieldDescription /> to add a description to the switch.
Focus is shared across devices, and turns off when you leave the app.
Card Style
Use a card-style layout with the switch for a more prominent display.
Form Integration
Integrate the switch into a form with proper validation and error handling.
Customizing Size
The switch size is controlled by the [--size-*] CSS variable.
API Reference
Switch
Toggle switch for on/off state. Use with a form control.
| Prop | Type | Default |
|---|---|---|
checked | boolean | - |
defaultChecked | boolean | false |
disabled | boolean | false |
invalid | boolean | false |
name | string | - |
value | string | number | "on" |
onCheckedChange | (details: CheckedChangeDetails) => void | - |
className | string | - |
| Attribute | Default |
|---|---|
--size | --spacing(4) |
For a complete list of props, see the Ark UI documentation.