Toggle
npx shadcn add @klarhimmel/toggleCopy for AIExamples
Basic
States
Toolbar
DetailsAbout, usage, props and more
A button that stays pressed: bold, favourite, mute.
When to use
Use for
A tool or preference that stays on: bold, favourite, mute.
Not for
A setting in a list. Use Switch. A choice submitted with a form. Use Checkbox.
Pairs with
Icons, Toggle group, Tooltip.
Preview
Import
Import
- Files
- toggle.tsx, in components/klarhimmel/ui/. With it: theme, utils. npm: radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
pressed / onPressedChange | boolean / (pressed: boolean) => void | - | Controlled or uncontrolled state. |
aria-label | string | - | Required for an icon-only toggle. |
disabled | boolean | false | Prevents interaction. |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Enter / Space | Presses or releases it |
Tab | Moves focus |
aria-pressed carries the state. An icon-only toggle needs an aria-label that stays the same when pressed.
Accessibility