Skip to content

Segmented toggle group

A segmented control whose pressed fill glides to the next pick.

A @khaeli/toggle-group for a single choice, with one difference: the selected segment's fill is one highlight that glides to the next pick. It jumps under reduced motion, and below 768px there is no track, so each item shows its own pressed fill. Its items are ToggleGroupItem. Like any toggle group it lets the selected segment be pressed off: keep one selected in onValueChange, as these examples do.

Single selection

With icons

Icon only

Disabled

Installation

npx shadcn@latest add @khaeli/segmented-toggle-group

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

Installs with

Keyboard

Tab
Moves into the group, to its first segment or to the one that last had focus, and out of it again. A disabled group leaves the tab order.
ArrowRightArrowLeft
Move focus to the next or previous segment, from the last round to the first. A disabled segment is passed over. The selection does not follow focus.
HomeEnd
Move focus to the first or last segment.
SpaceEnter
Select the focused segment.

Accessible name

  • The group is a role="group" of toggle buttons, not a radio group. Give it an aria-label that says what is being chosen, such as View.
  • Each segment's name is its text; an icon-only segment needs an aria-label. The selected segment is the one with aria-pressed="true".

Registry JSON

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