Button group
Related actions in one control: joined surface, floating tray, or expanding icons.
import { ButtonGroup } from '@uthereal/ui/button-group'Button group playground
Overview
ButtonGroup groups 1 to 12 related actions on the same object, such as message actions or canvas zoom controls. Each action item renders a native button with an action name or a link with href. Choose the visual and interaction model with layout:
| Layout | Role | Visual model | Key capabilities |
|---|---|---|---|
joined | group | Shared bordered surface with hairline dividers and gliding highlight | Trailing menu, live content values, collapseLabels, attached, tone |
floating | toolbar | Quiet translucent or raised (soft) tray with morphing highlight | pressed mode switches, { kind: 'separator' } clusters, shortcut, iconOnly |
expanding | toolbar | Compact pill of icons where the active item springs open to a label | defaultExpanded, in-place doneLabel check confirmation, tone="danger" |
Use ButtonGroup for frequent sibling actions. For one primary action with alternatives, use Button in split mode. For mutually exclusive options that stay selected, use Radio or Tabs. For more than about six actions, use DropdownMenu.
Usage
'use client'
import { ButtonGroup } from '@uthereal/ui/button-group'
export function MessageActions() {
return (
<ButtonGroup
label="Message actions"
items={[
{ id: 'copy', label: 'Copy', icon: 'copy', action: 'copy_message' },
{ id: 'edit', label: 'Edit', icon: 'pencil', action: 'edit_message' },
{
id: 'share',
label: 'Share',
icon: 'share-2',
action: 'share_message',
},
]}
onAction={(action, itemId) => console.log(action, itemId)}
/>
)
}label names the group for assistive technology and is not rendered visibly. onAction receives (action, itemId) when a user activates an action item. Layout-specific item fields are optional and ignored by other layouts, so the item shape stays consistent across all three modes.
Examples
Floating tray
Set layout="floating" for a toolbar of soft buttons with one shared morphing highlight. Use variant="outline" (default) for a quiet page toolbar or variant="soft" for a raised overlay toolbar. Add pressed for mode switches, { kind: 'separator' } between clusters, reserve to hold changing labels steady, and shortcut for tooltip hints.
Expanding pill
Set layout="expanding" for compact icon buttons where one item always shows its label (defaultExpanded, or the first enabled item). Pointing or focusing another item springs its label open while neighbours slide aside. Set doneLabel to confirm actions in place with a drawn check for confirmDuration (default 1400 ms), and tone="danger" for a destructive action.
Joined menu and live values
In the default joined layout, menu appends a chevron trigger that opens additional entries in a DropdownMenu. Use content to display a live value such as a zoom percentage while label remains the accessible name, and hideLabel for icon-only segments with Tooltip labels. Item icons accept names from the icon list.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
labelRequired | string— | Accessible name of the group, required because it is not shown: "Message actions", "Zoom". |
layout | joined | floating | expandingDefault: "joined" | The shape: joined (one surface, hairline dividers, a gliding highlight, an optional menu), floating (soft buttons in a quiet tray with a shared morphing highlight) or expanding (compact icon buttons; the active one springs open to its label). |
itemsRequired | ButtonGroupItem[]— | The buttons and separators, up to 12, in order. Action items: a stable unique id, a label, an optional icon, hideLabel for icon-only, reserve (other labels it can show, floating), content (a live value shown instead of the label, joined), pressed (a mode switch, floating), shortcut (a hint in its tooltip, floating), tone (danger for the destructive one, expanding), doneLabel (an in-place confirmation with a check, expanding), an action or an href, and disabled. Separators: { kind: "separator" } between logical clusters (floating). |
menu | ButtonGroupMenu— | A trailing chevron item, named by its label, that opens more entries in a dropdown menu aligned to the group end: actions with icons, links, checkboxes, radios, groups and separators. Each action reports its own id. Joined only. |
orientation | horizontal | verticalDefault: "horizontal" | A row or a column (joined, floating). |
attached | booleanDefault: true | Join the buttons into one control with shared edges. Off, they are separate buttons with an 8 pixel gap (joined). |
variant | outline | solid | softDefault: "outline" | Fill treatment (joined): outline by default, solid for an ink primary group, or soft with tone hairlines. Floating: outline and solid are quiet, soft raises the tray for overlays. |
tone | neutral | accentDefault: "neutral" | Color role. neutral is ink; accent follows the theme accent (joined). |
size | xs | sm | md | lgDefault: "md" | Height: 32, 36, 44, or 50 pixels, like a button of the same size. |
collapseLabels | booleanDefault: true | When a joined row does not fit its container, items with an icon drop their label (shown in a tooltip instead) until there is room again. |
iconOnly | booleanDefault: false | Show every item with an icon as an icon only; an item hideLabel wins (floating). |
tooltip | booleanDefault: true | Show the label of icon-only buttons in a tooltip on hover and keyboard focus. Not shown while disabled. |
tooltipPlacement | PlacementDefault: "top" | Preferred side of the tooltips. Collision detection flips them when there is no room. |
defaultExpanded | string— | The item whose label shows at rest, usually the primary one; defaults to the first enabled item (expanding). |
confirmDuration | integerDefault: 1400 | How long the in-place confirmation of an expanding item stays, in milliseconds; 1400 by default. |
disabled | booleanDefault: false | Every item and the menu unavailable and removed from the tab order. A single disabled item stays focusable. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | ButtonGroupTheme— | Color mode, accent, and semantic tokens. See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Press and swap animation preset. System reduced-motion preferences take precedence. |
motionOptions | ButtonGroupMotionOptions— | Press scale (joined items dip their content instead), and label swap duration (ms) and travel (px). |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
onAction(action, itemId) | Handle an item or menu action in your application. |
renderIcon(name, context) | Replace an item icon; context has size, slot (icon), and item. |
preset | Application defaults overridden by explicit instance props. |
tokens | CSS variables (--ui-*) applied after the typed theme. |
ref, className, style | Forwarded to the root group element. |
| Native attributes | id, aria-describedby, and event handlers on the root element. |
Keyboard & accessibility
Joined (role="group")
| Key | Interaction |
|---|---|
Tab | Moves through each item; every segment is its own tab stop. |
ArrowLeft, ArrowRight | Moves between segments, wrapping (ArrowUp/ArrowDown vertical). |
Home, End | Moves focus to the first or last segment. |
Enter, Space | Activates the focused segment or opens the trailing menu. |
Floating and expanding (role="toolbar")
| Key | Interaction |
|---|---|
Tab | Enters the toolbar on the roving tab stop (last focused or first enabled). |
ArrowLeft, ArrowRight | Moves focus between items, wrapping (ArrowUp/ArrowDown when vertical). |
Home, End | Moves focus to the first or last focusable item. |
Enter, Space | Activates the focused item. |
- Accessible names:
labelnames the root group or toolbar. Icon-only items and live-value items exposelabelviaaria-label. Tooltips only describe the trigger whenshortcutis set so screen readers do not hear the label twice. - Disabled states: A disabled item keeps
aria-disabled="true"and remains focusable injoinedandexpandinglayouts (skipped by arrows infloating). Settingdisabledon the group removes all items from the tab order. - Live announcements: A label change within 1 second of pressing an item announces once in a polite
role="status"region outside the buttons. Expanding confirmations announce through the same region and re-announce on repeat actions. - Touch and
:focus-visible: Onexpanding, keyboard focus expands only on:focus-visible, and touch uses a first tap to reveal the label and a second tap to activate. - RTL and forced colors: Horizontal arrow keys mirror in
dir="rtl". Underforced-colors: active, borders, dividers, separators, focus outlines, and active/pressed indicators use system colors.
Motion and theming
- Joined: A shared highlight glides between segments on the snappy spring while adjacent dividers fade. Pressing dips segment content (
0.97, icon-only0.9) while the outer surface stays fixed. - Floating: A shared highlight morphs between buttons on the morph spring, grows in from
0.94when appearing, and settles to0.965while pressed. Label changes crossfade with a short vertical rise and soft blur. - Expanding: Item width springs on the morph spring while the label slides out from behind the icon. Confirmations swap the icon for a drawn check and crossfade the word in place.
- Reduced motion:
motion="none"removes all transitions and press scales immediately.prefers-reduced-motion: reduceremoves travel, scale, and path drawing while keeping short opacity crossfades.
theme accepts the core color, radius, typography, and control-scale tokens plus controlOn, success, and component geometry tokens (trayPadding, trayGap, trayPaddingX, expandingPadding). Use UtherealProvider for shared defaults.
Composition
ButtonGroup is a leaf component. Every action item must reference a host-registered action (or navigate with href), and the host receives { componentId, itemId }. Separators carry no action.
{
"type": "ButtonGroup",
"props": {
"label": "Message actions",
"layout": "expanding",
"defaultExpanded": "copy",
"items": [
{
"id": "copy",
"label": "Copy",
"icon": "copy",
"doneLabel": "Copied",
"action": "copy_message"
},
{
"id": "delete",
"label": "Delete",
"icon": "trash-2",
"tone": "danger",
"doneLabel": "Deleted",
"action": "delete_message"
}
]
},
"children": []
}