Button Group
Related actions in one body of glass. The buttons share a single lens: point at any of them and the whole body swells.
Latest changeImprovedv1.5.7In the first example Snooze stands apart, in clear glass: it bends the grid behind it, and its rim mirrors the white glass on either side.
- v1.5.7ImprovedIn the first example Snooze stands apart, in clear glass: it bends the grid behind it, and its rim mirrors the white glass on either side.
- v1.5.0NewButton Group: related actions share one body of glass, side by side or stacked, with separators and text; nest groups to set some apart. It wears Button's glass, tinted white unless you colour it, in three sizes.
- All changes →
Use it for
- Two to five actions on the same thing: a message toolbar, map controls, a split button.
- A main action with its options next to it, divided by a separator.
Not for
- Choosing between options, where one stays selected: use Tabs.
- A single action: use Button.
- Unrelated actions: one body says they belong together.
Installation
npx shadcn@latest add https://onemorethink.dev/r/button-group.jsonUsage
import {
GlassButtonGroup,
GlassButtonGroupItem,
GlassButtonGroupSeparator,
GlassButtonGroupText,
} from '@/components/liquid-glass'
<GlassButtonGroup aria-label="Message">
<GlassButtonGroupItem onClick={archive}>Archive</GlassButtonGroupItem>
<GlassButtonGroupItem onClick={report}>Report</GlassButtonGroupItem>
<GlassButtonGroupSeparator />
<GlassButtonGroupItem aria-label="More"><Ellipsis /></GlassButtonGroupItem>
</GlassButtonGroup>The group is the glass, and the glass is Button's, with its light and shadow. It is tinted white, on light and dark pages alike, unless you colour it. Its items are plain buttons lying in it, with no glass of their own. Do not put a Button inside: a lens within a lens bends nothing. The items get no background of their own under the pointer: the glass answers for the whole group.
Together and apart
Nest groups to keep some actions in one body and others on their own. The outer group draws no glass: it only lays the inner ones out with space between them, and a group with a single item is a button standing apart.
<GlassButtonGroup aria-label="Message">
<GlassButtonGroup>
<GlassButtonGroupItem aria-label="Back" className="px-0"><ArrowLeft /></GlassButtonGroupItem>
</GlassButtonGroup>
<GlassButtonGroup>
<GlassButtonGroupItem>Archive</GlassButtonGroupItem>
<GlassButtonGroupItem>Report</GlassButtonGroupItem>
</GlassButtonGroup>
</GlassButtonGroup>With a menu
For the actions that do not fit, wrap one group in a Menu and put its trigger on the three dots with asChild: the group's glass grows into the menu and the dots go, and it runs back the same way. The example above does it. A Dropdown Menu works the same way. See Menu and Dropdown Menu.
API reference
| Prop | Type | Default |
|---|---|---|
orientationSide by side or stacked. | 'horizontal' | 'vertical' | 'horizontal' |
sizeHeight of a horizontal group: 32, 40 or 48 px. The items follow. | 'sm' | 'md' | 'lg' | 'md' |
materialTinted is white, or the colour of your own | 'tinted' | 'clear' | 'tinted' |
tintClear glass only: how much tint covers the backdrop (0–1). | number | 0.6 |
…restPassed to the group ( | div attributes | — |
GlassButtonGroupItem asChildRender the item on its single child element (a router | boolean | false |
GlassButtonGroupSeparatorA hairline between two items. It turns with the group. | className | — |
GlassButtonGroupTextText that is not a button. | span attributes | — |
Accessibility
- The group has
role="group": name it witharia-labeloraria-labelledby. - Every item is a real
<button>; Tab moves through them one by one, Enter and Space press. - Icon-only items need an
aria-label. Separators arerole="separator". - Without WebGL2 it keeps its plain CSS colour.