This page as markdown: /toggle.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

Toggle

Status: stable

Pressed-state button over Base UI Toggle, plus ToggleGroup for shared single- or multi-select rows. Pressed styling reads from data-[pressed].

Keywords: toggle, pressed, button state, toolbar, segmented control, segmented, toggle group, button group, view switcher

Usage

Use Toggle for button-like controls that can be pressed on or off within a toolbar or compact control set.

Best practices

Anatomy

Part Required Description
Toggle yes A single pressed or unpressed control.
ToggleGroup no A coordinated group of toggle choices.
ToggleGroupItem no One toggle inside a group — an alias of Toggle, so inside a ToggleGroup is the same thing.

Subcomponents

Name Type Description
ToggleGroup Base UI ToggleGroup props (value, defaultValue, onValueChange, multiple, disabled, orientation, loopFocus) + appearance?: "default" | "segmented" | "tiles" + motion?: "full" | "subtle" | "off" + className Groups child Toggles and shares pressed state across them — each Toggle inside carries a value. Defaults to multiple: false (single-select) — the fit for view-mode switches and segmented controls; pass multiple to allow several pressed at once, e.g. a row of formatting toggles.
ToggleGroupItem Alias of Toggle Re-export of Toggle for group composition — a Toggle carrying a value is the group item.

Props

Name Type Default Description
appearance "default" | "segmented" | "tiles" "default" On ToggleGroup: default is a loose row of toggles; segmented draws the capsule segmented control (one track, the pressed option filled) shared with ThemeSwitcher. Single-select segmented draws ONE fill that glides to the pressed option and resizes to its label, and always keeps an option chosen: pressing the chosen one does nothing. Multi-select keeps a fill per pressed option. tiles makes each toggle a stat tile (caption over figure), square and edge to edge, padded from the card's --card-p and divided by hairlines, with the pressed tile filled; single-select tiles also keep one chosen. Toggles inside inherit it.
stretch boolean false On ToggleGroup: run the whole width, sharing it equally between the toggles.
multiple boolean false On ToggleGroup: allow several toggles pressed at once. The default is single-select, which behaves like a radio group.
motion "full" | "subtle" | "off" "full" On ToggleGroup: how much motion this component uses: full (default) inherits the app's policy, subtle keeps feedback and drops the glide, off stills it. It can only turn motion down — it never overrides a reader's reduce-motion setting.
Toggle Base UI Toggle props (pressed, defaultPressed, onPressedChange, disabled, value) + className defaultPressed: false A two-state button. Uncontrolled via defaultPressed; controlled via pressed + onPressedChange. Pass value to identify it inside a ToggleGroup.

Variants

Tokens used

muted-foreground, foreground, accent, accent-foreground, card, border, ring

Motion

Accessibility

Related

Examples

Standalone

import { Toggle } from "@sableui/react"

<Toggle aria-label="Mute">Mute</Toggle>

Single-select group

import { Icon, Toggle, ToggleGroup } from "@sableui/react"

<ToggleGroup defaultValue={["list"]}><Toggle value="list" aria-label="List view"><Icon name="list" /></Toggle><Toggle value="grid" aria-label="Grid view"><Icon name="grid" /></Toggle></ToggleGroup>

Segmented view switch

import { Icon, Toggle, ToggleGroup } from "@sableui/react"

<ToggleGroup appearance="segmented" defaultValue={["list"]} aria-label="View"><Toggle value="list" aria-label="List view"><Icon name="list" /></Toggle><Toggle value="grid" aria-label="Grid view"><Icon name="grid" /></Toggle></ToggleGroup>

Segmented with labels, subtle motion

import { Toggle, ToggleGroup } from "@sableui/react"

<ToggleGroup appearance="segmented" motion="subtle" defaultValue={["week"]} aria-label="Range"><Toggle value="day">Day</Toggle><Toggle value="week">Week</Toggle><Toggle value="month">Month</Toggle></ToggleGroup>

Stat tiles that switch a chart

import { Card, Toggle, ToggleGroup } from "@sableui/react"

<Card className="overflow-hidden"><ToggleGroup appearance="tiles" defaultValue={["desktop"]} aria-label="Device"><Toggle value="desktop"><span className="text-caption text-muted-foreground">Desktop</span><span className="text-mono-lg">12,480</span></Toggle><Toggle value="mobile"><span className="text-caption text-muted-foreground">Mobile</span><span className="text-mono-lg">9,215</span></Toggle></ToggleGroup></Card>

Multi-select group

import { Toggle, ToggleGroup } from "@sableui/react"

<ToggleGroup multiple defaultValue={["bold"]}><Toggle value="bold">Bold</Toggle><Toggle value="italic">Italic</Toggle></ToggleGroup>