Skip to content

Button group

Expressive

Groups buttons as a unit; the connected variant replaces segmented buttons.

import { ButtonGroup } from '@windmorph/react';

Props

By name or description, across the 18 props below

ButtonGroup 18 props

  • varianttype "standard" | "connected"default "standard"

    standard spaces the buttons apart (18 / 12 / 8px by size); connected joins them 2px apart with shared inner corners across the container's width (the M3 Expressive replacement for segmented buttons). A standard group grows a pressed button into its neighbours' space; a connected one only changes its shape unless expandedRatio is set.

  • fullWidthtype booleandefault true

    Whether a connected group spans its container (M3's guidance, and the default). false sizes the group to its buttons, for one beside other controls; the buttons stay equally wide. Has no effect on a standard group or one with overflow.

  • sizetype "xs" | "sm" | "md" | "lg" | "xl"default "sm"

    Size shared by every button and icon button in the group; it also sets the spacing. Unset, the buttons keep their own (or an enclosing toolbar's) size.

  • shapetype "round" | "square"default "round"

    Shape shared by the buttons. A square connected group gives its outer corners the size of its inner ones (4 / 8 / 8 / 16 / 20px). Unset, the buttons keep their own.

  • buttonVarianttype "text" | "filled" | "elevated" | "tonal" | "outlined"default "filled"

    Variant shared by every Button in the group. filled, tonal and outlined reach the IconButtons too, so a group never mixes colour styles; a button's own variant wins. Unset, the buttons keep their own.

  • disabledtype booleandefault false

    Disables every button in the group.

  • selectionModetype "none" | "single" | "multiple"default "none"

    Lets toggle buttons with a value act as one selection. single behaves like radio buttons, multiple like checkboxes.

  • selectedKeystype Iterable<string>

    Controlled selection: the values of the selected toggle buttons.

  • defaultSelectedKeystype Iterable<string>

    Initial selection when uncontrolled.

  • deselectabletype booleandefault true

    The last selected button can be deselected, leaving none. false keeps at least one selected.

  • expandedRatiotype numberdefault 0.15, or 0 when variant is "connected"

    How much a pressed button grows, as a fraction of its width; its neighbours shrink by the same amount and the group keeps its width. 0 turns it off. Standard groups default to 0.15. Connected groups default to 0 (the spec: they "don't affect adjacent buttons", as in Compose's connected sample); set a ratio to opt in, as Compose can by combining a button group's animateWidth with the connected shapes. Under reduced motion there's no bump.

  • overflowtype booleandefault false

    Folds the trailing buttons that don't fit into a menu behind a trailing "More options" icon button (M3: "Buttons at the trailing edge of the button group can be customized to collapse into an overflow menu at smaller breakpoints"). The group then fills its container's width and re-measures as it resizes. Each folded button becomes a menu item with its label (an icon button's aria-label) and icon; disabled buttons stay disabled, and toggles show their selection. Choosing an item presses the button.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Events

  • onSelectionChangetype ((keys: Set<string>) => void)

    Called with the selected toggle buttons' values when the selection changes.

Text

  • labelstype Partial<ButtonGroupLabels>default { more: "More options" } A {@link LabelsProvider } sets them for the whole app.

    Text for assistive tech, e.g. the overflow indicator's name.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Built to the M3 Expressive button group spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Standard button group

    Built

    Variant · Standard

  • Connected button group

    Built

    Variant · Connected, Multiple

  • Size: XS, S, M, L, XL

    Built

    Configuration · Sizes

  • Shape: round and square

    Built

    Configuration · Sizes, Multiple

  • Selection: single-select

    Built

    Configuration · Connected

  • Selection: multi-select

    Built

    Configuration · Multiple

  • Selection: selection-required

    Built

    Configuration · Connected

  • Label buttons and icon buttons together

    Built

    Use case · Standard

  • Overflow menu at smaller widths

    Built

    Use case · Overflow

  • Density (web, chosen by the reader)

    Built

    Use case · Density

  • Press bump on connected groups

    Extension

    expandedRatio opts a connected group into the standard group's press bump. Not in the M3 spec, which keeps connected neighbours still; matches Google's Expressive showcase motion.

  • Shared button variant

    Extension

    buttonVariant sets the variant of every Button in the group through context, and of its IconButtons for the styles they have (filled, tonal, outlined); a button’s own variant wins.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • ButtonGroup: 41.9 kB

M3 Expressive specs

Sizes
xs, sm, md, lg, xl
Variants
standard, connected

Differences from Compose

  • Press expansion: the pressed item grows by expandedRatio of its width (0.15 in a standard group) while its neighbours shrink by the same amount, so the group's width stays constant. On the web the group watches each child's data-pressed and animates flex-basis on the fast spatial spring; expandedRatio=0 turns it off. A connected group defaults to 0, so only the pressed button's shape changes, unless you set a ratio.
  • Standard groups space their buttons 18 / 12 / 8 / 8 / 8px apart (XS–XL), so small buttons' 48px targets never overlap; at a higher density the XS and S gaps grow as the icon buttons shrink, keeping their centres 48px apart, and a group holding narrow icon buttons spaces them by the narrow width (48px minus it, where the spec's gap is smaller). Connected groups use a 2px gap and span their container, the buttons sharing its width equally, as Compose's weight(1f) does. The group is a grid of equal columns, so with w-fit it hugs its content and every button takes the widest one's natural width, labels keeping their full padding; add auto-cols-auto to size them by their labels instead. Outer corners are full, or the inner size in a square group; inner corners are 4 / 8 / 8 / 16 / 20px, 4px when pressed (2px at XS, whose corners rest at 4px); selected buttons become fully round; and XS and S connected icon buttons are at least 48px wide. These are logical corners, so they mirror in RTL.
  • Toggle buttons with a value join the group's React Aria toggle-group state; no-op selection changes that React Stately reports are not passed to onSelectionChange.
  • buttonVariant reaches icon buttons too when they have that style (filled, tonal, outlined), so a group never mixes styles; a button's own variant wins.
  • overflow is Compose's overflowIndicator with its default indicator (an icon button with more_vert and a "More options" tooltip). The menu items come from the folded buttons, and choosing one presses that button, so its own handler, link or selection runs. The group fills its container's width to measure it.
  • Under reduced motion the press bump doesn't happen and the corners snap.
  • Children must be direct Button / IconButton elements, since each is wrapped in its own context provider for its position.