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 change Improved v3.0.20 An icon item can show its word: give it reveal="Back" and, under the pointer or the keyboard's focus, the word comes in beside the icon while the body grows to it and the bodies beside it make room. It goes again after. The change is GlassReveal of glass-layer.tsx, which the header of a Toast list now uses too. In the first example Back and Snooze do it, and Archive and Report do on a phone, where they are icons.
- v3.0.20 Improved An icon item can show its word: give it
reveal="Back"and, under the pointer or the keyboard's focus, the word comes in beside the icon while the body grows to it and the bodies beside it make room. It goes again after. The change isGlassRevealofglass-layer.tsx, which the header of a Toast list now uses too. In the first example Back and Snooze do it, and Archive and Report do on a phone, where they are icons. - v2.2.2 Improved Button Group is now a toolbar, on UI SDK. Tab stops in it once, on the item focused last; the arrow keys move between its items (up and down in a vertical group), Home and End go to the ends. Nested groups share that one tab stop. A disabled item stays reachable with the arrow keys and does nothing when pressed, and
disabledon the group does the same for all of them;loop={false}stops the arrow keys from wrapping. The glass has not changed. Button Group now needs@ui-sdk/coreand@ui-sdk/react: the install command adds them. - v2.2.2 Fixed The separator of a horizontal group is drawn again. Its height was a share of a row that has no height of its own, which came to nothing; it is now half an item tall, in each size.
- v1.5.7 Improved In 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.0 New Button 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-svelte@latest add https://liquidglass.pulse.city/r/button-group.jsonThe group is a toolbar, and its behaviour (one tab stop, the arrow keys between its items, disabled items that stay reachable, ARIA) comes from UI SDK, so Button Group needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.
Usage
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>An icon that shows its word
Give an icon item its word with reveal: under the pointer, or with the keyboard's focus on it, the word comes in beside the icon and goes again after. Under a finger it comes in too, and stays a moment after the finger has lifted. The icon stays where it is; the body grows to make room for the word, in 320 ms that begin as gently as they end, and the bodies beside it move over, their glass with them. The word is the item's aria-label too, so it needs no other. The item is square at rest by itself: leave px-0 out. --glass-open: 1 on the item keeps the word shown, so a breakpoint class such as sm:[--glass-open:1] gives a label where there is room and an icon that shows its word where there is not. In the example above Back and Snooze are always icons, and Archive and Report are on a phone. The change is GlassReveal of glass-layer.tsx with keep; without it the word takes the icon's place, as in the header of a Toast list. Use it, with GLASS_REVEAL for the timing and followGlass for the glass beside it, for a button of your own.
<GlassButtonGroup aria-label="Message">
<GlassButtonGroup>
<GlassButtonGroupItem reveal="Back" onClick={back}><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 |
|---|---|---|
tempo On | 'default' | 'quick' | 'default' |
orientation Side by side or stacked. | 'horizontal' | 'vertical' | 'horizontal' |
size Height of a horizontal group: 32, 40 or 48 px. The items follow. | 'sm' | 'md' | 'lg' | 'md' |
material Tinted is white, or the colour of your own | 'tinted' | 'clear' | 'tinted' |
tint Clear glass only: how much tint covers the backdrop (0–1). | number | 0.6 |
disabled Stops every item from being used. They stay reachable with the arrow keys, so the group keeps its tab stop. | boolean | false |
loop Whether the arrow keys wrap from the last item to the first. Set it on the outermost group. | boolean | true |
…rest Passed to the group ( | div attributes | — |
GlassButtonGroupItem asChild Render the item on its single child element (a router | boolean | false |
GlassButtonGroupItem reveal The word of an item that is an icon: under the pointer or the keyboard's focus it comes in beside the icon, and goes again after; under a finger it stays a moment. It is the item's | string | — |
GlassButtonGroupSeparator A hairline between two items. It turns with the group. | className | — |
GlassButtonGroupText Text that is not a button. | span attributes | — |
Accessibility
- The group has
role="toolbar": name it witharia-labeloraria-labelledby. A group nested in it is agroupof the same toolbar. - Tab stops in the group once, on the item focused last. The arrow keys move between the items (up and down in a vertical group), Home and End go to the first and the last, and Tab leaves.
- Every item is a real
<button>: Enter and Space press it. A disabled item keeps its place among the arrow keys witharia-disabled, so a screen reader still finds it. - Icon-only items need an
aria-label. Separators arerole="separator". - Without WebGL2 it keeps its plain CSS colour.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.