Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Button Group for Astro

Joined Astro buttons that share a border and corner radius.

100%

Installation

bunx --bun shadcn@latest add @gnostic/button-group

Usage

---
import {
    ButtonGroup,
    ButtonGroupSeparator,
    ButtonGroupText,
} from "@/components/ui/button-group"
import { Button } from "@/components/ui/button"
---
<ButtonGroup aria-label="Document actions">
    <Button variant="outline">Save draft</Button>
    <ButtonGroupSeparator />
    <Button variant="outline">Preview</Button>
</ButtonGroup>

Set orientation="vertical" for a column. ButtonGroupText adds a label. ButtonGroupSeparator adds a divider. A horizontal group uses a vertical separator.

Composition

Place the parts directly inside ButtonGroup:

ButtonGroup
├── Button
├── ButtonGroupSeparator
├── Button
└── ButtonGroupText

ButtonGroupSeparator is optional. Its default orientation is vertical, which fits a horizontal group. Set orientation="horizontal" on the separator when the group is vertical.

API Reference

ButtonGroupProps

PropType
orientation?'horizontal' | 'vertical'

Direction of the joined controls.

Type'horizontal' | 'vertical'
Default"horizontal"

Div attributes such as class, id, and aria-label pass through.

ButtonGroupSeparator accepts Separator attributes such as class and orientation. ButtonGroupText accepts div attributes such as class.

Read the installed source for the component source.

When to use Button Group

Use Button Group when several buttons act on the same content and should read as one control. Put the group label in aria-label when nearby text does not name the group. Each button keeps its own label. Give an icon-only button an accessible name.

Keyboard and behavior

The group uses role="group". Each button keeps its own native keyboard behavior. This layout does not add arrow-key navigation or a pressed state. Use Toggle Group when the visitor keeps one option pressed.

Theme and layout

The outer buttons keep rounded corners. The inner edges join. Keep button sizes equal so the shared border stays even. Check visible focus around the shared borders, especially when a button is disabled.