Button group
ExpressiveGroups buttons as a unit; the connected variant replaces segmented buttons.
import { ButtonGroup } from '@windmorph/react';Props
ButtonGroup 18 props
standardspaces the buttons apart (18 / 12 / 8px by size);connectedjoins 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 unlessexpandedRatiois set.Whether a
connectedgroup spans its container (M3's guidance, and the default).falsesizes the group to its buttons, for one beside other controls; the buttons stay equally wide. Has no effect on astandardgroup or one withoverflow.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.
Shape shared by the buttons. A
squareconnected group gives its outer corners the size of its inner ones (4 / 8 / 8 / 16 / 20px). Unset, the buttons keep their own.Disables every button in the group.
Lets toggle buttons with a
valueact as one selection.singlebehaves like radio buttons,multiplelike checkboxes.Controlled selection: the
values of the selected toggle buttons.Initial selection when uncontrolled.
The last selected button can be deselected, leaving none.
falsekeeps at least one selected.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.
0turns 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'sanimateWidthwith the connected shapes. Under reduced motion there's no bump.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.Ref to the root element.
Events
Called with the selected toggle buttons'
values when the selection changes.
Text
Classes for each part.
classNames.rootis merged withclassName.Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
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.
| Item | Status | Details |
|---|---|---|
| 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. |
Standard button group
BuiltVariant · Standard
Size: XS, S, M, L, XL
BuiltConfiguration · Sizes
Selection: single-select
BuiltConfiguration · Connected
Selection: multi-select
BuiltConfiguration · Multiple
Selection: selection-required
BuiltConfiguration · Connected
Label buttons and icon buttons together
BuiltUse case · Standard
Overflow menu at smaller widths
BuiltUse case · Overflow
Density (web, chosen by the reader)
BuiltUse case · Density
Press bump on connected groups
ExtensionexpandedRatioopts 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
ExtensionbuttonVariantsets the variant of everyButtonin the group through context, and of itsIconButtons for the styles they have (filled, tonal, outlined); a button’s ownvariantwins.
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
expandedRatioof 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'sdata-pressedand animatesflex-basison the fast spatial spring;expandedRatio=0turns 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 withw-fitit hugs its content and every button takes the widest one's natural width, labels keeping their full padding; addauto-cols-autoto 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
valuejoin the group's React Aria toggle-group state; no-op selection changes that React Stately reports are not passed toonSelectionChange. buttonVariantreaches icon buttons too when they have that style (filled,tonal,outlined), so a group never mixes styles; a button's ownvariantwins.overflowis Compose'soverflowIndicatorwith its default indicator (an icon button withmore_vertand 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/IconButtonelements, since each is wrapped in its own context provider for its position.