UI

Button group

Related actions in one control: joined surface, floating tray, or expanding icons.

import { ButtonGroup } from '@uthereal/ui/button-group'

Button group playground

Loading interactive preview…

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:

LayoutRoleVisual modelKey capabilities
joinedgroupShared bordered surface with hairline dividers and gliding highlightTrailing menu, live content values, collapseLabels, attached, tone
floatingtoolbarQuiet translucent or raised (soft) tray with morphing highlightpressed mode switches, { kind: 'separator' } clusters, shortcut, iconOnly
expandingtoolbarCompact pill of icons where the active item springs open to a labeldefaultExpanded, 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.

ArgumentType / defaultDescription
labelRequiredstring—Accessible name of the group, required because it is not shown: "Message actions", "Zoom".
layoutjoined | 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).
itemsRequiredButtonGroupItem[]—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).
menuButtonGroupMenu—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.
orientationhorizontal | verticalDefault: "horizontal"A row or a column (joined, floating).
attachedbooleanDefault: trueJoin the buttons into one control with shared edges. Off, they are separate buttons with an 8 pixel gap (joined).
variantoutline | 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.
toneneutral | accentDefault: "neutral"Color role. neutral is ink; accent follows the theme accent (joined).
sizexs | sm | md | lgDefault: "md"Height: 32, 36, 44, or 50 pixels, like a button of the same size.
collapseLabelsbooleanDefault: trueWhen 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.
iconOnlybooleanDefault: falseShow every item with an icon as an icon only; an item hideLabel wins (floating).
tooltipbooleanDefault: trueShow the label of icon-only buttons in a tooltip on hover and keyboard focus. Not shown while disabled.
tooltipPlacementPlacementDefault: "top"Preferred side of the tooltips. Collision detection flips them when there is no room.
defaultExpandedstring—The item whose label shows at rest, usually the primary one; defaults to the first enabled item (expanding).
confirmDurationintegerDefault: 1400How long the in-place confirmation of an expanding item stays, in milliseconds; 1400 by default.
disabledbooleanDefault: falseEvery item and the menu unavailable and removed from the tab order. A single disabled item stays focusable.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeButtonGroupTheme—Color mode, accent, and semantic tokens. See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Press and swap animation preset. System reduced-motion preferences take precedence.
motionOptionsButtonGroupMotionOptions—Press scale (joined items dip their content instead), and label swap duration (ms) and travel (px).
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
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.
presetApplication defaults overridden by explicit instance props.
tokensCSS variables (--ui-*) applied after the typed theme.
ref, className, styleForwarded to the root group element.
Native attributesid, aria-describedby, and event handlers on the root element.

Keyboard & accessibility

Joined (role="group")

KeyInteraction
TabMoves through each item; every segment is its own tab stop.
ArrowLeft, ArrowRightMoves between segments, wrapping (ArrowUp/ArrowDown vertical).
Home, EndMoves focus to the first or last segment.
Enter, SpaceActivates the focused segment or opens the trailing menu.

Floating and expanding (role="toolbar")

KeyInteraction
TabEnters the toolbar on the roving tab stop (last focused or first enabled).
ArrowLeft, ArrowRightMoves focus between items, wrapping (ArrowUp/ArrowDown when vertical).
Home, EndMoves focus to the first or last focusable item.
Enter, SpaceActivates the focused item.
  • Accessible names: label names the root group or toolbar. Icon-only items and live-value items expose label via aria-label. Tooltips only describe the trigger when shortcut is set so screen readers do not hear the label twice.
  • Disabled states: A disabled item keeps aria-disabled="true" and remains focusable in joined and expanding layouts (skipped by arrows in floating). Setting disabled on 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: On expanding, 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". Under forced-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-only 0.9) while the outer surface stays fixed.
  • Floating: A shared highlight morphs between buttons on the morph spring, grows in from 0.94 when appearing, and settles to 0.965 while 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: reduce removes 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": []
}

On this page