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).
| Part | Class | Role |
|---|---|---|
| Container | .btn-group | Bordered row, clips item corners |
| Item | .btn-group__item | Segment button (42px min-height) |
| Icon | .btn-group__icon | 20px mask icon inside item |
| Label | .btn-group__label | Visible text beside icon |
| Icon-only | .btn-group--icon | Square icon buttons |
| Selected | .btn-group__item--selected | Primary surface + on-action text |
Prerequisites
- PimentCSS installed, Installation.
- Icons,
btn-group__iconslot 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.
<div class="btn-group" role="group" aria-label="View mode"><button type="button" class="btn-group__item" aria-pressed="false">
<i class="ph ph-list btn-group__icon" style="font-size:20px" aria-hidden="true"></i>
<span class="btn-group__label">List view</span>
</button><button type="button" class="btn-group__item btn-group__item--selected" aria-pressed="true">
<i class="ph ph-folder btn-group__icon" style="font-size:20px" aria-hidden="true"></i>
<span class="btn-group__label">Grid view</span>
</button></div>
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.
// See docs-site/src/lib/button-group-behavior.ts (single-select, radiogroup, optional multi-toggle).
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
| Class | Description |
|---|---|
.btn-group | Inline flex container, 1px border, 4px radius |
.btn-group--icon | Icon-only items (min-width 42px) |
.btn-group__item | Segment button; right divider between items |
.btn-group__item--selected | Active segment (primary background) |
.btn-group__item--hover | Doc-only hover preview |
.btn-group__item--disabled | Disabled look (prefer disabled attribute) |
.btn-group__icon | 20px icon slot (fills item color) |
.btn-group__label | Text label beside icon |
Customize (Sass)
-
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 ); -
Rebuild CSS
Run after editing _button-group.scss or tokens.npm run build:css
Accessibility (RGAA / WCAG)
Grouped buttons
- Name,
aria-labelon.btn-grouporaria-labelledbypointing to visible text. - Single selection,
role="radiogroup"+role="radio"+aria-checked, orrole="group"+aria-pressedon a single active item. - Icon-only, each button needs
aria-label; keeparia-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-visibleoutline is built in; do not remove it. - Disabled, use
disabledoraria-disabled="true"and avoid handlers on inactive items.