Base · Actions
Toggle group
A set of toggles where one or several can be pressed.
Props
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { KanbanIcon, ListIcon, MapIcon } from "lucide-react"
<ToggleGroup defaultValue={["list"]} aria-label="Shipment view">
<ToggleGroupItem value="list">
<ListIcon />
List
</ToggleGroupItem>
<ToggleGroupItem value="board">
<KanbanIcon />
Board
</ToggleGroupItem>
<ToggleGroupItem value="map">
<MapIcon />
Map
</ToggleGroupItem>
</ToggleGroup>Overview
A toggle group manages a row or column of toggles as one value. By default only one item can be pressed at a time; with multiple, any number can. Variant and size are set once on the group and apply to every item.
When to use
- To switch how the same data is shown, such as List, Board or Map.
- For a small set of formatting or filter options in a toolbar where several can be active together (set multiple).
- When there are two to five short options and all of them should stay visible.
When not to use
- When each option shows different content with its own panel: use Tabs.
- For a required single choice in a form: use a Radio group or Select.
- For actions that run once and do not stay pressed: use a Button group.
Anatomy
Group
The container. Holds the value and passes variant, size and spacing to its items.
Item
A toggle with a value. Pressed items take a muted fill.
Icon or label
Each item holds a short label, an icon, or both. Icon-only items need an accessible name.
Props
The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "outline" | default | Applied to every item. Outline adds a border. |
| size | "sm" | "default" | "lg" | default | Height of every item. |
| orientation | "horizontal" | "vertical" | horizontal | Layout direction. Also sets which arrow keys move focus. |
| spacing | number | 2 | Gap between items in spacing units. Set to 0 to join the items into one segmented control. |
| multiple | boolean | false | Allows more than one item to be pressed at once. |
| disabled | boolean | false | Disables every item in the group. |
| value | node | – | Array of pressed item values (controlled). Use defaultValue for uncontrolled. Always an array, also in single mode. |
| onValueChange | function | – | Called with the new array of pressed values. |
States
- Item off
- Transparent background.
- Item on
- Muted background; aria-pressed is true.
- Focus-visible
- 3px focus ring on the focused item, raised above its neighbors.
- Disabled
- All items at 50% opacity with no pointer events.
Accessibility
Role: group
| Keys | Action |
|---|---|
| Tab | Moves focus into the group, then out of it. The group is a single tab stop. |
| ArrowRight/ArrowLeft | In a horizontal group, moves focus to the next or previous item, wrapping at the ends. |
| ArrowDown/ArrowUp | In a vertical group, moves focus to the next or previous item, wrapping at the ends. |
| Home/End | Moves focus to the first or last item. |
| Enter/Space | Presses or releases the focused item. |
- Give the group an aria-label that names what is being chosen, such as “Shipment view”.
- In single mode the pressed item can be released, leaving nothing selected. If one option must always be active, enforce it in onValueChange or use a Radio group.
- Moving focus with arrow keys does not change the value; the user confirms with Enter or Space.
Design tokens
Change any of these in Foundations and this component follows, in every language.
Platform notes
- HTML / JS
- Planned
- Not built in HTML / JS yet.
- React
- Stable
- Matches the contract with no platform differences.
- React Native
- Draft
- A row or column of Pressables sharing one value array; each item reports accessibilityState.selected. There is no arrow-key roving focus on touch.
- Swift (SwiftUI)
- Planned
- Not built in Swift yet.
- Godot
- Planned
- Not built in Godot yet.
- Vue
- Draft
- Usage snippet only; same props and behavior as the React component.
- Svelte
- Draft
- Usage snippet only; same props and behavior as the React component.
- Solid
- Draft
- Usage snippet only; same props and behavior as the React component.