Toggle
A two-state button that can be either on or off.
Installation#
pnpm dlx shadcn@latest add @davinciui/toggleUsage#
API Reference#
| Prop | Type | Default |
|---|---|---|
variantVisual variant. | "default" | "outline" | "default" |
sizeSize of the toggle. | "default" | "sm" | "lg" | "default" |
pressedControlled pressed state. | boolean | — |
defaultPressedDefault pressed state. | boolean | false |
disabledDisables the toggle. | boolean | false |
classNameAdditional CSS classes. | string | — |
Accessibility#
Renders a native button with aria-pressed reflecting state, so Enter and Space toggle it and screen readers announce pressed or not pressed. Focus-visible ring and disabled styling are included.
Motion#
No meaningful motion; transition-all only smooths background, border, and text colors on state change. There is no duration or easing prop and no prefers-reduced-motion handling.
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.

