Actions

Toggle

A button that stays pressed. For one on/off setting, such as bold, where a checkbox would feel like a form.

packages/design-system/components/ui/toggle.tsx

Examples

Default and outline
Sizes: sm, default, lg
With a label
Disabled

Anatomy

  1. 01Button with aria-pressed
  2. 02Icon or label
  3. 03Muted fill when pressed

Usage

import { Toggle } from "@repo/design-system/components/ui/toggle";

<Toggle aria-label="Bold" pressed={bold} onPressedChange={setBold}>
  <BoldIcon />
</Toggle>

Props

PropTypeDefaultDescription
variant"default" | "outline""default"Outline adds a border so it reads as a control at rest.
size"default" | "sm" | "lg""default"36, 32 and 40px, at least square.
pressed / defaultPressedbooleannoneControlled or uncontrolled pressed state. Pressed fills with muted.
onPressedChange(pressed: boolean, details) => voidnoneCalled when it is toggled.
classNamestringnoneMerged last with cn(). Use it for layout (width, margin), not to restyle the component.

Guidance

Do

  • Label icon-only toggles with aria-label.

Don't

  • Use it to trigger an action. A toggle holds a state.