Skip to content

Toggles

Toggle is a pressable button that holds an on/off state, styled from the shared toggleVariants. Reach for it for a standalone binary control such as a formatting button (bold) or a show/hide switch where the state is conveyed by the button looking pressed. For a set of related toggles use Segmented Controls instead.

Live demo

The interactive story below runs from the deployed Storybook.

Usage

Source: toggle.tsx

import { Toggle } from "@beacon/design-system";
// Default
<Toggle>Toggle</Toggle>
// Outline variant
<Toggle variant="outline">Outline Toggle</Toggle>
// Starts pressed (uncontrolled)
<Toggle defaultPressed>Pressed</Toggle>
// Disabled
<Toggle disabled>Disabled</Toggle>

Props

Toggle forwards every prop from the Radix Toggle.Root and adds the variant props below.

PropTypeDefaultDescription
variant"default" | "outline""default"Visual style. outline adds a border.
size"default" | "sm" | "lg""default"Control height and padding.
pressedboolean—Controlled on/off state. Pair with onPressedChange.
defaultPressedbooleanfalseUncontrolled starting state.
onPressedChange(pressed: boolean) => void—Fires when the pressed state changes.
disabledbooleanfalseGreys out and blocks interaction.
childrenReactNode—Icon or short label shown inside the button.
classNamestring—Extra classes on the root.

The toggleVariants helper is also exported for composing custom toggle-styled elements.

When to use

  • A single on/off control where the pressed appearance carries the meaning (bold, mute, pin).
  • Icon-only buttons that retain a state, such as a star/favorite toggle.
  • Toolbar buttons that should look depressed while active.

Do not use Toggle for a labeled settings on/off where a clear track-and-knob affordance is expected; use the Switch component there. For mutually exclusive choices in a row, use Segmented Controls.