# ButtonGroup

> A labelled group of buttons with joined borders, a vertical orientation and group-wide variant, tone, size and disabled defaults.

Canonical: https://salmonui.dev/docs/buttons/button-group

```tsx
import { Button, ButtonGroup } from '@salmonui/buttons/button';
import '@salmonui/buttons/button/styles.css';

<ButtonGroup aria-label="Clipboard" variant="outline">
  <Button>Cut</Button>
  <Button>Copy</Button>
  <Button>Paste</Button>
</ButtonGroup>;
```

`ButtonGroup` groups related buttons into one labelled control. It renders
`<div role="group">`, named by `aria-label` or `aria-labelledby`.

- `orientation`: `'horizontal'` (default) or `'vertical'`.
- `attached` (default `true`) joins borders and shares corners; `false`
  spaces the buttons.
- `variant`, `tone`, `size` and `disabled` on the group are the defaults of
  every button inside; a button's own prop wins.
  Group `disabled` also follows a surrounding `<fieldset disabled>`.
- Ghost groups (`variant="ghost"`) are supported with joined borders;
round buttons follow the Button rule (no shape props).
- The group adds no keyboard model: every button is its own tab stop and
  Enter / Space activate it. For one tab stop with arrow keys use a
  [`ToggleButtonGroup`](https://salmonui.dev/docs/buttons/toggle-button-group).

- `MenuButton` and `SplitButton` can be group children, also in a vertical
  group; see
  [Split Button](https://salmonui.dev/docs/buttons/split-button#in-a-button-group). The group
  inherits `dir` and uses logical CSS, so it mirrors under `dir="rtl"`.
- The group has no state and no events of its own; it renders on the server
  like any element. `.salmon-button-group` carries `data-orientation` and
  `data-attached`, and `className`, `style` and other DOM props reach the
  `<div>`.

### Live demo: Button groups

Live demo: https://salmonui.dev/demos/buttons/button-group

Attached and spaced groups, a vertical group, group styles inherited by the buttons with per-button overrides, and a disabled group.

`Demo.tsx`:

```tsx
'use client';

import { Button, ButtonGroup } from '@salmonui/buttons/button';

// Attached and spaced groups, a vertical group and per-button overrides.
export default function ButtonGroupDemo() {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'flex-start', gap: 16 }}>
      <ButtonGroup aria-label="Clipboard" variant="outline">
        <Button>Cut</Button>
        <Button>Copy</Button>
        <Button>Paste</Button>
      </ButtonGroup>
      <ButtonGroup aria-label="Record" tone="primary">
        <Button>Save</Button>
        <Button tone="danger">Delete</Button>
      </ButtonGroup>
      <ButtonGroup aria-label="Navigation" orientation="vertical" variant="ghost">
        <Button>Inbox</Button>
        <Button>Drafts</Button>
        <Button>Sent</Button>
      </ButtonGroup>
      <ButtonGroup aria-label="Dialog actions" attached={false}>
        <Button>Cancel</Button>
        <Button tone="primary">Confirm</Button>
      </ButtonGroup>
      <ButtonGroup aria-label="Disabled group" disabled>
        <Button>One</Button>
        <Button>Two</Button>
      </ButtonGroup>
    </div>
  );
}
```

## Rendering

The group is a component, not a decoration applied to existing DOM after
mount, so it renders on the server like the buttons inside it.
Per-button options go on the `Button` children.

## API reference

[`ButtonGroup`](https://salmonui.dev/docs/reference/buttons/button/ButtonGroup) and
`ButtonGroupProps` in [`@salmonui/buttons/button`](https://salmonui.dev/docs/reference/buttons/button).
