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.jsonRevenue today: $1,820
Horizontal and vertical
Any Button variant works inside; keep one size in a group.
import { ButtonGroup } from "@/components/sheenui/button-group/button-group";
import { Button } from "@/components/sheenui/button/button";
// Package build (after the first npm release, or a packed tarball): import { Button, ButtonGroup } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
return (
<div className="flex flex-col items-start gap-5">
<ButtonGroup aria-label="View">
<Button variant="glass">Day</Button>
<Button variant="glass">Week</Button>
<Button variant="glass">Month</Button>
</ButtonGroup>
<ButtonGroup aria-label="Actions" orientation="vertical">
<Button variant="outline" size="sm">Copy</Button>
<Button variant="outline" size="sm">Paste</Button>
<Button variant="outline" size="sm" disabled>Cut</Button>
</ButtonGroup>
</div>
);
}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
Keyboard
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
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .