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.
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
npm install @vitrumui/reactUsage
import {
GlassButtonGroup,
GlassButtonGroupItem,
GlassButtonGroupSeparator,
GlassButtonGroupText,
} from '@vitrumui/react/button-group'
<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 Dropdown Menu and put its trigger on the three dots: the list stretches out of the whole group, as Select's does out of its button. See Dropdown Menu.
Examples
Coming soon
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.