Switch
A control that allows the user to toggle between checked and not checked.
Installation#
pnpm dlx shadcn@latest add @davinciui/switchUsage#
API Reference#
| Prop | Type | Default |
|---|---|---|
checkedChecked state. | boolean | — |
defaultCheckedDefault checked. | boolean | false |
disabledDisables the switch. | boolean | false |
invalidMarks as invalid. | boolean | false |
sizeSize variant. | "default" | "sm" | "lg" | "default" |
classNameAdditional CSS classes. | string | — |
Accessibility#
A native button with role switch, aria-checked, optional aria-invalid, disabled support, and a focus-visible ring. Space and Enter toggle it, but no label or description is generated, so callers must associate visible text or aria-label.
Motion#
The thumb translates horizontally and the track changes color through CSS transitions. No timing or easing props exist and prefers-reduced-motion is not detected, so the thumb movement remains under reduced motion.
View source
Click the icon in the preview toolbar to browse source for each variant.
Keep in mind
This component is inspired by various open-source projects and patterns. Please verify licenses and implementation details before using in production.
Need a custom component?
I build bespoke UI components & websites tailored to your brand.

