Button group
A row of joined buttons for related actions, shown as one control.
import { ButtonGroup } from '@halo-ds/react';
When to use it
Use a button group for a few actions that belong together, like Copy, Share and Download, a split button with a dropdown, or zoom controls. Items are joined into one pill with thin dividers. In Figma, add or remove items in the Items slot without detaching.
Do
- Group two to five related actions.
- Keep every item the same size.
- Give icon-only items an accessible name and a Tooltip.
- Put the most common action first.
Don't
- Use a button group to pick one option; use a Segmented control.
- Mix unrelated actions in one group.
- Put a Primary or Destructive button inside a group.
- Let a group wrap onto two lines.
Button group or Segmented control?
They look alike. A button group runs actions; a segmented control picks one option.
- Button group: Each item runs an action, like Copy or Share. Nothing stays selected after a click. For toolbars, split buttons and zoom controls.
- Segmented control: Picks one option from a set, like Day, Week or Month. One option is always selected. For switching views, modes or filters.
Props
ButtonGroup props
| Prop | Type | What it does | |
|---|---|---|---|
size | `ButtonSize \ | undefined` | Sets the size of every button in the group. Figma: Size. |
aria-label (required) | string | Names the group for screen readers, such as "File actions". | |
children (required) | ReactNode | Button elements. They are shown as joined Secondary buttons. Figma: Items slot. |
It also takes the usual HTML attributes for its element.
Examples
Overview
import { Button, ButtonGroup } from '@halo-ds/react';
export default function Example() {
return (
<ButtonGroup aria-label="Range">
<Button variant="secondary">Day</Button>
<Button variant="secondary">Week</Button>
<Button variant="secondary">Month</Button>
</ButtonGroup>
);
}
Sizes
Every button in the group takes the group size.
import { Button, ButtonGroup } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-stack">
{(['sm', 'md', 'lg'] as const).map((size) => (
<ButtonGroup key={size} size={size} aria-label="Range">
<Button>Day</Button>
<Button>Week</Button>
<Button>Month</Button>
</ButtonGroup>
))}
</div>
);
}
With icons
Text with icons, icon only and mixed. Icon-only items need an aria-label.
import { Button, ButtonGroup } from '@halo-ds/react';
import { Copy, DownloadSimple, Minus, Plus, ShareNetwork } from '@phosphor-icons/react';
export default function Demo() {
return (
<div className="demo-stack">
<ButtonGroup aria-label="File actions">
<Button iconLeft={<Copy />}>Copy</Button>
<Button iconLeft={<ShareNetwork />}>Share</Button>
<Button iconLeft={<DownloadSimple />}>Download</Button>
</ButtonGroup>
<ButtonGroup aria-label="Zoom">
<Button iconOnly aria-label="Zoom out"><Minus /></Button>
<Button>100%</Button>
<Button iconOnly aria-label="Zoom in"><Plus /></Button>
</ButtonGroup>
</div>
);
}
Disabled item
A disabled item keeps its borders, so the group still reads as one control.
import { Button, ButtonGroup } from '@halo-ds/react';
export default function Demo() {
return (
<ButtonGroup aria-label="Edit">
<Button>Undo</Button>
<Button disabled>Redo</Button>
<Button>Clear</Button>
</ButtonGroup>
);
}
More: https://halodesignsystem.dev/components/button-group