# Button Group

## Usage

`ButtonGroup` connects related buttons into one group. Buttons have no gap. Separators distinguish adjacent buttons:

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { ButtonGroup } from '@astryx-vue/core/ButtonGroup'
</script>

<template>
  <ButtonGroup label="Editing actions">
    <Button label="Copy" />
    <Button label="Cut" />
    <Button label="Paste" />
  </ButtonGroup>
</template>
```

On a touch-first device such as a phone or tablet, a press tracks like a menu for a finger or a pen: press a button and slide across the others, and the highlight follows. The button you lift on runs, and lifting outside the group runs nothing. A mouse press acts as a native button's. A menu trigger in the group (with `aria-haspopup`) keeps its own opening. The group grows its buttons' tap targets toward 44 px, stopping halfway to the nearest interactive neighbor outside the group; a tap in that band goes to the nearest button.

### Anatomy

- **Button**: One or more Button or IconButton elements that form the connected group.
- **Divider**: A thin border between buttons, rendered automatically by the group.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Group buttons that perform related actions on the same object, like copy, cut, paste on selected text. |
| Do | Use the same variant for all buttons in a group so they look like a single connected unit. |
| Do | Keep groups small (2–4 buttons). For more actions, use a Toolbar or DropdownMenu instead. |

## Examples

### Basic

Three related actions joined into a single connected control. Provide a group label for accessibility and keep all buttons the same variant so they read as one unit.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { ButtonGroup } from '@astryx-vue/core/ButtonGroup'
</script>

<template>
  <ButtonGroup label="Text editing actions">
    <Button label="Copy" />
    <Button label="Cut" />
    <Button label="Paste" />
  </ButtonGroup>
</template>
```

### Floating

A grouped action bar raised with elevation="med". The connected buttons share one surface, so the shadow lifts them as a unit.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { ButtonGroup } from '@astryx-vue/core/ButtonGroup'
import { Stack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <Stack direction="vertical" :gap="3" h-align="start">
    <Text type="supporting" color="secondary">
      The whole group shares one raised surface — a floating action bar
    </Text>
    <ButtonGroup label="Zoom controls" elevation="med">
      <Button label="Zoom out" />
      <Button label="Reset" />
      <Button label="Zoom in" />
    </ButtonGroup>
  </Stack>
</template>
```

## ButtonGroup Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | required | Accessible name for the group. |
| `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Connected direction and arrow-key navigation axis. |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Default inherited by child buttons. An explicit child size wins. |
| `elevation` | `'none' \| 'low' \| 'med' \| 'high'` | `'none'` | Shadow depth for the connected surface. |
| `isDisabled` | `boolean` | `false` | Disables every Button and IconButton in the group. Members stay focusable and the group keeps its Tab stop. |

## Slot

ButtonGroup receives Button or IconButton through its required default slot.

## Keyboard navigation

| Key | Behavior |
| --- | --- |
| Left and Right Arrow | Move focus within a horizontal group. |
| Up and Down Arrow | Move focus within a vertical group. |
| `Home` | Focus the first available button. |
| `End` | Focus the last available button. |

- The group is a single Tab stop. A disabled member is marked `aria-disabled` rather than natively disabled, so it stays focusable.
- When every member is disabled, the Tab stop stays on one disabled member, so keyboard users can still reach the group.
- Right-to-left horizontal layouts reverse the Left and Right Arrow behavior.

## Template ref

`ButtonGroup` exposes `element`.
Its type is `HTMLDivElement | null`.

## Native attributes

The root element receives:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.
- Native event listeners.

## Accessibility

### Text label

- Criterion: 1.4.3 Contrast (Minimum)
- Check: 4.5:1
- States: Rest, Hover, Pointer down

Text in each button must have at least 4.5:1 contrast with its background in every state. For Hover and Pointer down, measure the final background after the overlay is applied.

### Essential icon or spinner arc

- Criterion: 1.4.11 Non-text Contrast
- Check: 3:1
- States: Icon only, Loading

An icon used instead of text must have at least 3:1 contrast with the button background. The moving spinner arc must also meet 3:1. An icon beside a visible label does not need its own check.

### Visible control boundary

- Criterion: 1.4.11 Non-text Contrast
- Check: 3:1 if needed
- States: Rest

Some groups need a divider or edge to show each button. That divider or edge must have at least 3:1 contrast.

### Keyboard focus indicator

- Criterion: 1.4.11 Non-text Contrast
- Check: 3:1
- States: Focus visible

The focus outline must have at least 3:1 contrast with the area around it.

### Disabled appearance

- Criterion: 1.4.3 and 1.4.11 exceptions
- Check: Not required
- States: Disabled

Disabled controls do not need to meet these contrast ratios.
