# Button group

Groups related buttons into one control, or joins a main action with its options as a split button.

- Family: action
- Import: `import { ButtonGroup } from "@senvenli/react/action";`
- Page: https://design.senvenli.com/docs/components/button-group
- JSON: https://design.senvenli.com/docs/components/button-group.json

## Example: Related actions

Two to four buttons that act on the same thing, joined into one unit.

```tsx
import { Button, ButtonGroup } from "@senvenli/react/action";

export default function Example() {
  return (
    <ButtonGroup aria-label="Invoice actions">
      <Button iconBefore="download">Download</Button>
      <Button iconBefore="printer">Print</Button>
      <Button iconBefore="mail">Send</Button>
    </ButtonGroup>
  );
}
```

## Examples

### Split button

A main action with a second button for its alternatives.

```tsx
import { Button, ButtonGroup } from "@senvenli/react/action";

export default function Example() {
  return (
    <ButtonGroup aria-label="Send" variant="split">
      <Button variant="primary">Send invoice</Button>
      <Button variant="primary" iconOnly iconBefore="chevron-down" aria-label="More send options" />
    </ButtonGroup>
  );
}
```

### Icon buttons

Each button keeps its own accessible name; the group has one too.

```tsx
import { Button, ButtonGroup } from "@senvenli/react/action";

export default function Example() {
  return (
    <ButtonGroup aria-label="History">
      <Button iconOnly iconBefore="undo-2" aria-label="Undo" />
      <Button iconOnly iconBefore="redo-2" aria-label="Redo" />
    </ButtonGroup>
  );
}
```

## Guidelines

### When to use it

- Two to four related actions belong together.
- A main action has a menu of variants (split).

### Use something else when

- [toggle-button](https://design.senvenli.com/docs/components/toggle-button.md): The buttons hold a pressed state, such as a view or format choice.
- [toolbar](https://design.senvenli.com/docs/components/toolbar.md): A longer row of controls above a list or editor.

## Accessibility

Built in:

- Exposed as a group.

You provide:

- An `aria-label` that names the group.

## API reference

### ButtonGroup

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| variant | `"default" \| "split"` | `"default"` | no | `split`: a primary main action with an icon button that opens a menu of alternatives; the seam uses the pressed brand fill instead of `ds-border`. |

Also takes 275 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-brand-bold-pressed`, `--ds-border`

## Related

- [button](https://design.senvenli.com/docs/components/button.md)
