ButtonGroup
Groups related buttons into one connected control
Usage
import {Button, ButtonGroup} from "@peakui/react";Put <ButtonGroup.Separator /> inside each button after the first to draw the divider between neighbors.
Buttons inherit size, variant, isDisabled and fullWidth from the group; a button's own prop wins.
Examples
Variants
Sizes
Orientation
The orientation prop arranges the buttons in a row or a column, and the group reads it from an enclosing React Aria toggle button group provider when the prop is omitted.
With Icons
Full Width
Disabled State
Without Separator
Omit <ButtonGroup.Separator /> and the buttons sit flush without dividers.
Customization
Tailwind CSS
<ButtonGroup className="gap-2">
<Button>First</Button>
<Button>
<ButtonGroup.Separator />
Second
</Button>
</ButtonGroup>Global CSS
@layer components {
.button-group {
@apply gap-2 rounded-lg;
}
.button-group__separator {
@apply opacity-25;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The ButtonGroup component uses these CSS classes (view source styles):
Base & Orientation Classes
.button-group- Base group styles.button-group--horizontal- Buttons in a row (default).button-group--vertical- Buttons in a column
Modifier Classes
.button-group--full-width- Stretches the group to the container's width
Element Classes
.button-group__separator- Divider between adjacent buttons
Slots
[data-slot="button-group"][data-slot="button-group-separator"]
Interactive States
The group itself has no interactive states; it restyles the states of the buttons inside it:
- Pressed:
:activeor[data-pressed](the pressed scale is removed for a cohesive group) - Focus:
:focus-visibleor[data-focus-visible](the focused button is raised above its neighbors)
API Reference
ButtonGroup
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | Arranges the buttons in a row or a column |
fullWidth | boolean | false | Stretches the group and every button inside to the container's width |
isDisabled | boolean | - | Disables the group; every button inside inherits it, and a button's own isDisabled wins |
variant | 'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft' | - | Inherited by every button inside; a button's own variant wins |
size | 'sm' | 'md' | 'lg' | - | Inherited by every button inside; a button's own size wins |
children | React.ReactNode | - | Buttons to group together |
className | string | (values: GroupRenderProps) => string | - | Additional classes, or a function of the group's state |
render | DOMRenderFunction<'div', GroupRenderProps> | - | Replaces the rendered element. It must still return a <div> |
Every other React Aria Group prop is accepted.
ButtonGroup.Separator
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Separator content; renders nothing by default |
className | string | - | Additional classes |
render | DOMRenderFunction<'span', undefined> | - | Replaces the rendered element. It must still return a <span> |
The separator is aria-hidden="true": it decorates the boundary and carries no meaning on its own.
Render Props
When children or className of the group is a function, it receives:
| Prop | Type | Description |
|---|---|---|
isHovered | boolean | Whether the group is hovered |
isFocusWithin | boolean | Whether any button inside is focused |
isFocusVisible | boolean | Whether the focus inside was moved by keyboard |
isDisabled | boolean | Whether the group is disabled |
isInvalid | boolean | Whether the group is marked invalid |