Skip to main content

Installation

npx shadcn@latest add @eo-n/button-group

Usage

Import all parts and piece them together.
import {
  ButtonGroup,
  ButtonGroupSeparator,
  ButtonGroupText,
} from "@/components/ui/button-group";
import { Button } from "@/components/ui/button";
<ButtonGroup>
  <Button>First</Button>
  <Button>Second</Button>
  <Button>Third</Button>
</ButtonGroup>

Examples

Horizontal Group

<ButtonGroup orientation="horizontal">
  <Button variant="outline">Bold</Button>
  <Button variant="outline">Italic</Button>
  <Button variant="outline">Underline</Button>
</ButtonGroup>

Vertical Group

<ButtonGroup orientation="vertical">
  <Button variant="outline">Top</Button>
  <Button variant="outline">Middle</Button>
  <Button variant="outline">Bottom</Button>
</ButtonGroup>

With Separator

<ButtonGroup>
  <Button variant="outline">Copy</Button>
  <Button variant="outline">Cut</Button>
  <ButtonGroupSeparator />
  <Button variant="outline">Paste</Button>
</ButtonGroup>

With Text Label

<ButtonGroup>
  <ButtonGroupText>View:</ButtonGroupText>
  <Button variant="outline">Grid</Button>
  <Button variant="outline">List</Button>
</ButtonGroup>

With Icons

<ButtonGroup>
  <Button variant="outline" size="icon">
    <AlignLeft className="h-4 w-4" />
  </Button>
  <Button variant="outline" size="icon">
    <AlignCenter className="h-4 w-4" />
  </Button>
  <Button variant="outline" size="icon">
    <AlignRight className="h-4 w-4" />
  </Button>
</ButtonGroup>

Component API

ButtonGroup

Container for grouping related buttons together.
orientation
'horizontal' | 'vertical'
default:"horizontal"
The orientation of the button group. Determines how buttons are arranged and how borders are removed between adjacent buttons.
className
string
Additional CSS classes to apply to the button group container.

ButtonGroupSeparator

Visual separator between button groups or sections within a group.
orientation
'horizontal' | 'vertical'
default:"vertical"
The orientation of the separator. Should match the button group’s orientation for proper alignment.
className
string
Additional CSS classes to apply to the separator.

ButtonGroupText

Text label or description within a button group.
asChild
boolean
default:false
When true, merges props with the immediate child element instead of rendering a div wrapper.
className
string
Additional CSS classes to apply to the text element.

Features

  • Seamless Integration: Automatically handles border radius and border removal between adjacent buttons
  • Orientation Support: Works in both horizontal and vertical layouts
  • Focus Management: Proper z-index handling ensures focused buttons appear above adjacent buttons
  • Flexible Composition: Mix buttons, separators, text labels, and other elements
  • Accessible: Uses proper ARIA role="group" for screen readers

Accessibility

The button group uses role="group" to indicate a set of related controls. Ensure each button within the group has appropriate labels or aria-labels for screen reader users.
  • Button - Individual button component
  • Toggle Group - Grouped toggle buttons with single or multiple selection
  • Toolbar - More complex toolbar with various control types

Build docs developers (and LLMs) love