Skip to main content

button group

A container that groups related button like elements together with consistent styling.

Philosophy

Individual buttons sometimes belong together. ButtonGroup handles the visual joining — shared borders, connected radii, consistent spacing — so you don't manually manage CSS for grouped actions. It's a layout primitive, not a logic primitive: each button inside still owns its own behavior.

How It's Built

Loading diagram...

Installation


npx @gentleduck/cli add button-group

npx @gentleduck/cli add button-group

Usage

import {
  ButtonGroup,
  ButtonGroupSeparator,
  ButtonGroupText,
} from "@/components/ui/button-group"
import {
  ButtonGroup,
  ButtonGroupSeparator,
  ButtonGroupText,
} from "@/components/ui/button-group"
<ButtonGroup>
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</ButtonGroup>
<ButtonGroup>
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</ButtonGroup>

Accessibility

  • The ButtonGroup component has the role attribute set to group.
  • Use Tab to navigate between the buttons in the group.
  • Use aria-label or aria-labelledby to label the button group.
<ButtonGroup aria-label="Button group">
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</ButtonGroup>
<ButtonGroup aria-label="Button group">
  <Button>Button 1</Button>
  <Button>Button 2</Button>
</ButtonGroup>

ButtonGroup vs ToggleGroup

  • Use the ButtonGroup component when you want to group buttons that perform an action.
  • Use the ToggleGroup component when you want to group buttons that toggle a state.

Examples

Orientation

Set the orientation prop to change the button group layout.

Size

Control the size of buttons using the size prop on individual buttons.

Nested

Nest <ButtonGroup> components to create button groups with spacing.

Separator

The ButtonGroupSeparator component visually divides buttons within a group.

Buttons with variant outline do not need a separator since they have a border. For other variants, a separator is recommended to improve the visual hierarchy.

Split

Create a split button group by adding two buttons separated by a ButtonGroupSeparator.

Input

Wrap an Input component with buttons.

Input Group

Wrap an InputGroup component to create complex input layouts.

Create a split button group with a DropdownMenu component.

Select

Pair with a Select component.

Popover

Use with a Popover component.

API Reference

ButtonGroup

PropTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'Layout direction of the button group
dir'ltr' | 'rtl'--Text direction override. Resolved via useDirection (dir prop -> DirectionProvider -> 'ltr').
classNamestring--Additional class names to apply
childrenReact.ReactNode--Grouped content (buttons, separators, text, or nested groups)
...propsReact.HTMLProps<HTMLDivElement>--Additional props to spread to the content div

ButtonGroupSeparator

PropTypeDefaultDescription
orientation'horizontal' | 'vertical''vertical'Orientation of the separator line
classNamestring--Additional class names to apply
...propsReact.ComponentPropsWithoutRef<typeof Separator>--Additional props inherited from Separator.

ButtonGroupText

PropTypeDefaultDescription
asChildbooleanfalseIf true, uses the Slot component instead of rendering a div
classNamestring--Additional class names to apply
childrenReact.ReactNode--Text content to display
...propsReact.HTMLProps<HTMLDivElement>--Additional props to spread to the content div

RTL Support

Direction is resolved through the shared primitives direction module. Use a local dir="rtl" override when the component exposes it, or set DirectionProvider at app/root level for global RTL/LTR behavior.