Demos

An icon toggle. Give it an aria-label.

Usage

Use a toggle for a two-state action on the current item, like bookmark or favourite. For a setting, use a Switch. For a one-off action, use a Button.

Import it from @workspace/ui/components/toggle.

Anatomy

  • Toggle — A button with aria-pressed. Pressed toggles get a muted background.

Notes

  • Icon-only toggles need an aria-label. Keep the label the same in both states. The pressed state is announced for you.
  • Put data-icon="inline-start" or data-icon="inline-end" on an icon next to text so the padding stays even.
  • toggleVariants is exported to style other elements like a toggle.

Examples

Outline

Set variant="outline" to show the edge when off.

Sizes

sm, default, and lg.

With text

An icon and a label. Mark the icon with data-icon.

Disabled

A toggle that cannot be pressed.

Controlled

Hold the state with pressed and onPressedChange.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

Toggle

PropTypeDefaultDescription
variant"default" or "outline"defaultVisual style.
size"sm", "default", or "lg"defaultHeight and padding.
defaultPressedbooleanfalsePressed on first render.
pressedboolean—Pressed state when controlled.
onPressedChange(pressed) => void—Called when the state changes.
disabledbooleanfalseBlocks input and dims the toggle.