Skip to content

Toggle group

A group of toggles, joined or segmented, on Base UI ToggleGroup.

One item is pressed at a time unless the group is multiple; value and defaultValue are arrays either way. From 768px wide, foundation draws every horizontal group as one 30px segmented track, whatever its variant, size and spacing. Those three show below that width and in vertical groups.

Single selection

Multiple selection

Vertical

Outline and joined

Sizes

Disabled

Installation

npx shadcn@latest add @khaeli/toggle-group

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0
  • class-variance-authority ^0.7.1

Keyboard

Tab
Moves into the group, to its first item or to the item that last had focus, and out of it again. The group is one tab stop. A disabled group leaves the tab order.
ArrowRightArrowLeft
In a horizontal group, move focus to the next or previous item, from the last round to the first. A disabled item is passed over. Nothing is pressed until you press it.
ArrowDownArrowUp
Do the same in a group with orientation="vertical". Each pair of arrows does nothing in the other orientation.
HomeEnd
Move focus to the first or last item.
SpaceEnter
Press or release the focused item. In a single-selection group pressing an item releases the one before it, and pressing the pressed item leaves none.

Accessible name

  • The group is a role="group". Give it an aria-label that says what is being chosen, such as Range.
  • Each item's name is its text; an icon-only item needs an aria-label. Whether it is pressed is aria-pressed, set by the item.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/toggle-group.json