Skip to main content
PimentCSS v1.0.1, what's new
Home

Button group

Segmented single-select and optional multi-toggle toolbars.

Overview

.btn-group is an inline flex row of .btn-group__item buttons sharing one outer border. Add .btn-group--icon when every item is icon-only (square min-width). The active segment uses .btn-group__item--selected and the matching ARIA attribute (aria-pressed or aria-checked).

PartClassRole
Container.btn-groupBordered row, clips item corners
Item.btn-group__itemSegment button (42px min-height)
Icon.btn-group__icon20px mask icon inside item
Label.btn-group__labelVisible text beside icon
Icon-only.btn-group--iconSquare icon buttons
Selected.btn-group__item--selectedPrimary surface + on-action text

Prerequisites

  • PimentCSS installed, Installation.
  • Icons, btn-group__icon slot with Phosphor (ph()) or any SVG library.
  • Buttons, same action tokens as standalone Buttons (hover, focus, disabled).

Button item

Each segment is a <button type="button">. Doc-only modifiers --hover show spec states; interactive demos rely on real hover and your script for selection.

  • Default
  • Hover (spec)
  • Selected
  • Disabled

Structure

Wrap items in .btn-group with role="group" for toolbars or multi-toggle segments, or role="radiogroup" when only one option may be active. Icon + text pairs use .btn-group__icon and .btn-group__label.

Default group

Segmented control with one selected item; siblings use aria-pressed="false". Icons sit before labels when you need both.

Toggle (radiogroup)

When only one option may be active, prefer role="radiogroup" with role="radio" and aria-checked on items.

Single choice: role="radiogroup" and aria-checked on each item.

Icon-only group

Add .btn-group--icon and a distinct aria-label on each button (search, add, bookmark, home below). The active item uses aria-pressed="true".

Behavior in your app

Copy and adapt docs-site/src/lib/button-group-behavior.ts after PimentCSS CSS is loaded. This site calls wireAllButtonGroups() from doc-client.ts for blocks with data-button-group-live.

Interactive example

Click a segment to select it. Arrow Left and Arrow Right move focus and update the single selected item in this live demo.

Class reference

ClassDescription
.btn-groupInline flex container, 1px border, 4px radius
.btn-group--iconIcon-only items (min-width 42px)
.btn-group__itemSegment button; right divider between items
.btn-group__item--selectedActive segment (primary background)
.btn-group__item--hoverDoc-only hover preview
.btn-group__item--disabledDisabled look (prefer disabled attribute)
.btn-group__icon20px icon slot (fills item color)
.btn-group__labelText label beside icon

Customize (Sass)

  1. Button group spacing

    Override padding, gap, and icon size before importing components.
    @use "pimentcss-design-system" with (
      $btn-group-item-px: 1rem,
      $btn-group-item-py: 0.5rem,
      $btn-group-item-gap: 0.5rem,
      $btn-group-icon-size: 1.25rem
    );
  2. Rebuild CSS

    Run after editing _button-group.scss or tokens.
    npm run build:css

Accessibility (RGAA / WCAG)

Grouped buttons

  • Name, aria-label on .btn-group or aria-labelledby pointing to visible text.
  • Single selection, role="radiogroup" + role="radio" + aria-checked, or role="group" + aria-pressed on a single active item.
  • Icon-only, each button needs aria-label; keep aria-hidden="true" on decorative icons.
  • Keyboard, Tab focuses each segment; Arrow Left/Right should move selection in single-select groups (provide in JS).
  • Focus, :focus-visible outline is built in; do not remove it.
  • Disabled, use disabled or aria-disabled="true" and avoid handlers on inactive items.

Next steps