Button Group

A row of related actions on one shared surface

Composablebuilt onButton

A button group puts related actions on one surface, like a file's share, duplicate, and archive, or an editor's undo and redo. A highlight glides between the buttons as you hover or tab along the row.

When one button stays selected, use ToggleGroup. When the row needs arrow-key navigation, use Toolbar.

Preview

Installation

Usage

Composition

Leave variant unset on the buttons inside; they take the group's style.

A shell never gets narrower than its buttons. If it may not fit on small screens, put it in a container that scrolls sideways, such as a ScrollArea with nativeScroll. To let a field shrink instead, pass className="min-w-0" to the group.

Examples

Variants

Use variant to pick the shell the buttons sit on.

VariantDescription
outlineAn outline Button's fill and border.
softThe default. A secondary Button's fill, no edge.
elevatedA raised surface, for toolbars that float.
solidThe neutral fill, for a primary action and options.
attachedNo shell; joins buttons to fields. See Attached.

Separator

Use ButtonGroupSeparator to split actions into clusters; it hides beside the highlight.

Emphasis

Give one button a variant to mark the main action; it keeps its own fill.

Pill

Set [--radius:9999px] on the group for a pill; the buttons' corners follow.

With Text

Use ButtonGroupText for a read-only label between buttons, like a selection count. For a value people type or step, use NumberField.

3 selected

With Fields

Put an Input or Select in a shell and it drops its border to sit in the row like a button.

With Dropdown

Pair an action with a menu of related ones; the trigger keeps the highlight while the menu is open.

Orientation

Set orientation="vertical" to stack the buttons; separators turn to match.

Size

Use size to match the group's height to a Button of the same size. Icon-only buttons still need an icon size to stay square.

Nested

Nest groups to lay out several shells; inner groups inherit the outer variant and size.

Attached

Use variant="attached" to join buttons, inputs, and selects into one control, with their own borders and variants.

Keep every part of an attached group in one style. These examples pair outline fields (variant="outline") with outline buttons, so the shared edges separate the parts. For a filled group, pair filled fields with field buttons, which share the field's tint, and use a tonal button for the action.

Accessibility

Labels

The group renders role="group". Give it an aria-label that names the set ("File actions"), and give every icon-only button its own.

Keyboard

Tab moves through the buttons one at a time. For arrow-key navigation along a long row, use Toolbar.

Highlight

The highlight follows the pointer and keyboard focus and skips disabled buttons. Focus also draws a ring, so the highlight is never the only cue. With reduced motion, it jumps instead of sliding. Browsers without CSS anchor positioning show a hover color on each button instead.

API Reference

Button Group is a custom component built from plain HTML elements; every prop below is specific to it. Each part also accepts the props of the element it renders.

Props

ButtonGroup

Groups buttons on one surface. Renders a div with role="group".

ButtonGroupSeparator

A line between buttons. Wraps Separator.

ButtonGroupText

A read-only segment for a label or value. Renders a div; pass render={<label />} to label an input in an attached group.

Upgrading

If you're reinstalling over an earlier version, check these changes:

BeforeNow
Installed as cubby-ui/button-group.tsxInstalls into a cubby-ui/button-group/ folder with button-group.css. Import from @/components/ui/cubby-ui/button-group/button-group and delete the old file.
Children fused into one bordered controlThe default is soft, a filled shell. Pass variant="attached" for the old look.
ButtonGroupSeparator defaulted to verticalIt turns perpendicular to the group, so vertical groups need no orientation.
Buttons in a group set variant="outline"Leave variant unset in a shell. A set variant marks the button as the main action.