Skip to content

Toggle Group

Buttons that stay pressed: one on its own, or a toolbar group where one or several can be on at a time.

On this page
Used for
  • Text formatting
  • Alignment buttons
  • View mode switch
  • Filter by tag

Examples

Installation

npx knowns-ui@latest add toggle-group
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

type
"single" | "multiple"
single: value is string | null (at most one pressed). multiple: value is string[].
value / defaultValue / onValueChange
string | null · string[]
Defaultnull / []
Pressed items, controlled or not.
required
boolean
Defaultfalse
Single only: pressing the pressed item keeps it pressed.
aria-label
string
Required name of the toolbar (role="toolbar", aria-orientation).
options
{ value, label?, icon?, disabled?, tooltip?, aria-label? }[]
Items as data. Icon-only items use tooltip as their name when there's no aria-label.
children
<ToggleGroupItem value icon? tooltip? disabled?>
Or items as direct children.
variant
"outline" | "ghost"
Default"outline"
Outline: card segments with hairlines. Ghost: quiet toggles (in a light tray when attached).
size
"sm" | "md"
Default"md"
28 or 32px high (taller on touch screens).
attached
boolean
Defaulttrue
Joined segments, or separate toggles with a small gap.
orientation
"horizontal" | "vertical"
Default"horizontal"
Also picks the arrow keys: ← → or ↑ ↓.
disabled
boolean
Defaultfalse
Disables every item.
Keyboard
-
One tab stop. Arrows / Home / End move focus (skipping disabled, wrapping); Space or Enter presses. Arrows never change the value.
Toggle.pressed / defaultPressed / onPressedChange
boolean
Defaultfalse
aria-pressed state, controlled or not.
Toggle.icon / variant / size / tooltip
ReactNode / variant / size / ReactNode
Default - / "ghost" / "md"
Without children it's square; give it an aria-label.

Picking one of a few modes, like a tab bar, where something is always selected? Use SegmentedControl: a radio group with a sliding thumb where arrows change the value. Use ToggleGroup when items are switches that can be on or off.

What it handles

  1. 01Renders independent aria-pressed buttons inside a role toolbar, from an options array or from ToggleGroupItem children.
  2. 02Runs in single mode, which swaps the pressed item and clears it on a second press unless required, or in multiple mode, which toggles each item.
  3. 03Gives the group one tab stop, moves focus with the arrows that match the orientation plus Home and End, and skips disabled items.
  4. 04Joins items into one segmented outline with shared hairlines by default, or spaces them with attached set to false, horizontally or vertically.
  5. 05Uses an item tooltip as the accessible name of an icon-only item when no aria-label is given.
  6. 06Exports a standalone Toggle for a single pin or mute button, plus the helpers nextPressed and rovingTarget for tests.

States

First render
Nothing. Pressed items paint in their pressed look
none
Press
The item gains a soft tint, a firmer ring and full ink; the previous item in single mode returns to muted
120ms, ease out
Hover
An unpressed item takes a faint background and full ink
120ms, ease out
Roving focus
Focus moves to the next enabled item and the ring follows it
none, at once
Disabled
The item dims and ignores the pointer
none, at once
Reduced motion
Colour changes land at once
0ms

Works with

When to use

When to use

  • Toolbars with pressable options, single or multiple, such as text formatting or filters.

When not to use

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Toggle Group to my app and wire it to my own data.
  • I need toolbars with pressable options, single or multiple, such as text formatting or filters. Set that up with the Knowns UI Toggle Group.
  • Which Toggle Group props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "toggle-group" }) and search_docs({ query: "toggle group" }).

Need help?

Stuck on Toggle Group, or found something off? We read every message.