Skip to content

React Button Group

A React button group that joins related buttons into one control, with attached corners and arrow-key roving focus. Use ButtonGroup to join related buttons into one control: a Day, Week, Month switch, a split action, or an editor toolbar with Cut, Copy and Paste.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button-group.json

Revenue today: $1,820

Horizontal and vertical

Any Button variant works inside; keep one size in a group.

Files to copy

4 folders · 4 files · 4 packages
From theme/src/
  • components/button-group/
  • hooks/{use-direction.ts, use-latest.ts}
  • lib/{cn.ts, form.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button-group.jsonRegistry item: button-group. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • hooks/{use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Props

PropTypeDefaultDescription
aria-labelstringNoneAccessible name of the group, e.g. "Text alignment". Give one when the buttons only make sense together.
orientation"horizontal" | "vertical""horizontal"Direction of the row and of the arrow keys.

Keyboard

KeysAction
TabFocuses the group once, on the button that was last focused (the first at first).
←/→Move to the previous or next button (↑ / ↓ when vertical). It wraps.
Home/EndJump to the first or last button.
Enter/SpacePress the focused button.

Accessibility

  • The group is role="group"; name it with aria-label when the buttons only make sense together ("View", "Text alignment").
  • Each button keeps its own name and state: use aria-pressed on toggle buttons. Disabled buttons are skipped by the arrow keys.
  • Roving focus keeps a long toolbar to one tab stop. Targets stay 44px on touch screens.
  • In right-to-left pages the arrow keys follow the reading direction.

When to use the button group

  • Use ButtonGroup for a Day, Week, Month switch above a chart, a split action with a dropdown caret, or the Cut, Copy and Paste buttons of an editor toolbar.
  • Use orientation="vertical" for a stacked group, for example next to a sidebar; the arrow keys follow the direction.
  • Give the group an aria-label so the role="group" has a name, and give toggle buttons aria-pressed so their state is announced.
  • Skip it when the choice is exclusive and belongs to a form. Use SegmentedControl for one of a few values and Toggle or ToggleGroup for pressed states.
  • Pair it with Tooltip on icon-only buttons and DropdownMenu for a split button's menu.

Button group, toggle group or segmented control?

The three look alike and answer different questions. ButtonGroup joins buttons that each run their own action (Copy, Paste, Cut). ToggleGroup keeps a pressed state for each button, for formatting such as bold and italic. SegmentedControl holds exactly one selected value and belongs in a form. Pick by what the control remembers: nothing, a set of pressed buttons, or one value.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .