Button group
Related buttons spaced apart or attached into one bar, sharing a size and variant.
Demo
Usage
import { Button, ButtonGroup, Input } from '@tuttn/slant'
// Spaced: a set of related actions, named for assistive technology.
<ButtonGroup label="Draft actions">
<Button>Discard</Button>
<Button variant="primary">Publish</Button>
</ButtonGroup>
// Attached: one bar with shared borders. Size and variant reach every button,
// unless a button sets its own.
<ButtonGroup attached variant="primary" label="Merge">
<Button>Merge</Button>
<ButtonGroup.Separator />
<Button icon aria-label="More merge options"><ChevronDownIcon /></Button>
</ButtonGroup>
// A text cell and an input join the bar too.
<ButtonGroup attached size="sm" label="Pages">
<Button icon aria-label="Previous page"><ChevronLeftIcon /></Button>
<ButtonGroup.Text>2 of 5</ButtonGroup.Text>
<Button icon aria-label="Next page"><ChevronRightIcon /></Button>
</ButtonGroup>
<ButtonGroup attached label="Share link">
<Input readOnly defaultValue="tuttn.io/t/24" aria-label="Link" />
<Button>Copy</Button>
</ButtonGroup>
// A column.
<ButtonGroup attached orientation="vertical" size="sm" label="Sort">…</ButtonGroup>Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | The group's accessible name, for a set of related actions such as "Text alignment". |
attached | boolean | false | Joins the buttons into one bar with shared borders, instead of spacing them apart. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | A row of buttons, or a column. |
size | 'sm' | 'md' | 'lg' | — | The size every button inside takes, unless it sets its own. |
variant | 'primary' | 'secondary' | 'ghost' | — | The variant every button inside takes, unless it sets its own. |
ButtonGroup.Separator | HTMLAttributes<HTMLDivElement> | — | A hairline between buttons (role="separator", aria-orientation across the group). In an attached bar it sits on the shared border, which matters between solid primary buttons. |
ButtonGroup.Text size | 'sm' | 'md' | 'lg' | the group's size | A static, non-focusable cell drawn in a button's box, for a count ("1 of 5") or a unit; it takes the attached corners like a button. |
…rest | HTMLAttributes | — | className, style, other attributes and the ref go on each part's own element: the role="group" div, the separator div and the text span. |
The group is a role="group" element named by label; give one whenever the buttons belong to a single task ("Text alignment", "Pages"), so a screen reader announces it on the way in. Every button keeps its own tab stop: for a set of options with one tab stop and arrow keys, use a ToggleGroup instead, which is built on the same context.
Inside a group, a Button's size and variant default to the group's, and in an attached group it renders data-attached with the group's orientation, which squares its inner corners and overlaps the borders it shares. An Input does the same, so a field can sit between buttons. A hovered or focused member rises above its neighbours so its whole border and focus ring show.