Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
variant
size
import { Toggle } from "@/components/ui/toggle";<Toggle aria-label="Bold">Bold</Toggle>Installation
$ pnpm dlx shadcn@latest add @synccn/toggleFirst time in this project? Connect synccn with one command.
Usage
import { Toggle } from "@/components/ui/toggle";<Toggle aria-label="Bold"><Bold /></Toggle>API reference
Generated from the component's TypeScript types, so it always matches the code.
Toggle
A two-state button: pressed or not.
PropTypeDescription
- pressed
booleanControlled state.
- defaultPressed
booleanDefault
falseInitial state when uncontrolled.
- onPressedChange
(pressed: boolean) => voidCalled with the new state.
- variant
"default" | "outline"Default
"default"Border style.
- size
"sm" | "default" | "lg"Default
"default"Size.
- className
stringExtra classes for the root element.
- children
React.ReactNodeContent to render.
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
- Reports its state with aria-pressed.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-pressed
- Shows a visible focus ring for keyboard users
More inputs
ButtonSeven variants, four sizes and a built-in loading state.InputText field with optional leading icon and invalid state.TextareaMulti-line field that grows with its content and counts characters.CheckboxChecked, unchecked and indeterminate, with label and description.SwitchToggle with a springy thumb in three sizes.Radio GroupPick one option, shown as dots or as selectable cards.