PeakUI

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: :active or [data-pressed] (the pressed scale is removed for a cohesive group)
  • Focus: :focus-visible or [data-focus-visible] (the focused button is raised above its neighbors)

API Reference

ButtonGroup

PropTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'Arranges the buttons in a row or a column
fullWidthbooleanfalseStretches the group and every button inside to the container's width
isDisabledboolean-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
childrenReact.ReactNode-Buttons to group together
classNamestring | (values: GroupRenderProps) => string-Additional classes, or a function of the group's state
renderDOMRenderFunction<'div', GroupRenderProps>-Replaces the rendered element. It must still return a <div>

Every other React Aria Group prop is accepted.

ButtonGroup.Separator

PropTypeDefaultDescription
childrenReact.ReactNode-Separator content; renders nothing by default
classNamestring-Additional classes
renderDOMRenderFunction<'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:

PropTypeDescription
isHoveredbooleanWhether the group is hovered
isFocusWithinbooleanWhether any button inside is focused
isFocusVisiblebooleanWhether the focus inside was moved by keyboard
isDisabledbooleanWhether the group is disabled
isInvalidbooleanWhether the group is marked invalid

On this page