Auto-sync
Changes sync every minute
Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
import { Switch } from "@/components/ui/switch";<Switch label="Email digests" />Installation
$ pnpm dlx shadcn@latest add @synccn/switchFirst time in this project? Connect synccn with one command.
Usage
import { Switch } from "@/components/ui/switch";<Switch label="Auto-sync" defaultChecked />API reference
Generated from the component's TypeScript types, so it always matches the code.
- checked
booleanControlled state.
- defaultChecked
booleanDefault
falseInitial state when uncontrolled.
- onCheckedChange
(checked: boolean) => voidCalled with the new state.
- label
React.ReactNodeClickable label.
- size
"sm" | "default" | "lg"Default
"default"Track size.
- disabled
booleanPrevents changes.
- id
stringId for the control; generated if omitted.
- className
stringExtra classes for the root element.
Also accepts every standard <button> attribute, and forwards its ref.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
Keyboard
- SpaceorEnterToggle
Accessibility
- role switch with aria-checked. Give it a visible label or aria-label.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: switch
- ARIA attributes: aria-checked
- Shows a visible focus ring for keyboard users
- Labels are tied to their controls