Dropdown Menu
A menu of actions that swells out of the control that opens it as one body of glass: a button of its own, or a whole Button Group.
Use it for
- A handful of actions on one thing, kept out of the way until asked for: Rename, Duplicate, Delete.
- The overflow of a Button Group: the three dots at its end.
Not for
- Picking a value that stays selected: use Select.
- Two or three actions that fit on screen: show them in a Button Group.
- Several of these on one screen: one stretching list is a moment, many are noise.
Installation
npm install @vitrumui/reactThe behaviour (keyboard, typeahead, focus, positioning, ARIA) comes from UI SDK, so Dropdown Menu 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 {
GlassDropdownMenu,
GlassDropdownMenuContent,
GlassDropdownMenuItem,
GlassDropdownMenuSeparator,
GlassDropdownMenuTrigger,
} from '@vitrumui/react/dropdown-menu'
<GlassDropdownMenu>
<GlassDropdownMenuTrigger>Options</GlassDropdownMenuTrigger>
<GlassDropdownMenuContent>
<GlassDropdownMenuItem onSelect={rename}>Rename</GlassDropdownMenuItem>
<GlassDropdownMenuItem onSelect={duplicate}>Duplicate</GlassDropdownMenuItem>
<GlassDropdownMenuSeparator />
<GlassDropdownMenuItem destructive onSelect={remove}>Delete</GlassDropdownMenuItem>
</GlassDropdownMenuContent>
</GlassDropdownMenu>It is Select's motion on a list of actions: the list swells out of the whole trigger, the neck between them stretches and snaps, and the items arrive one after another; closing plays it backwards. The trigger wears Button's clear glass, so it needs something behind it to bend.
Out of a Button Group
Wrap one group and the content in the menu, and put the trigger on one of the group's items with asChild. The whole group is then the anchor: the list swells out of its body and takes its colour, white included. Wrap only the group that opens the menu.
<GlassDropdownMenu>
<GlassButtonGroup>
<GlassDropdownMenuTrigger asChild>
<GlassButtonGroupItem aria-label="More" className="px-0"><Ellipsis /></GlassButtonGroupItem>
</GlassDropdownMenuTrigger>
</GlassButtonGroup>
<GlassDropdownMenuContent>
<GlassDropdownMenuItem>Mark as read</GlassDropdownMenuItem>
<GlassDropdownMenuItem destructive>Delete</GlassDropdownMenuItem>
</GlassDropdownMenuContent>
</GlassDropdownMenu>API reference
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeOn | boolean / boolean / (open: boolean) => void | — |
GlassDropdownMenuTrigger asChildPut the trigger on its single child (a | boolean | false |
GlassDropdownMenuContent side / alignWhere the list opens against the trigger: below and centred by default. It flips when there is no room. | 'top' | 'bottom' / 'start' | 'center' | 'end' | 'bottom' / 'center' |
GlassDropdownMenuContent sideOffsetThe gap between the control and the list, where the neck stretches. | number | 12 |
GlassDropdownMenuItem onSelectRuns when the item is pressed; the menu then closes ( | () => void | — |
GlassDropdownMenuItem destructivePaints the item red, for Delete. | boolean | false |
GlassDropdownMenuItem disabledDimmed and skipped by the keyboard. | boolean | false |
GlassDropdownMenuSeparatorA hairline between items. | className | — |
Accessibility
- A button with
aria-haspopupthat opens amenuofmenuitems (the WAI-ARIA menu button pattern). - Arrow keys, Home and End move through the items, typing a letter jumps to a match, Enter runs the item, Escape closes and returns focus to the trigger.
- An icon-only trigger needs an
aria-label. - With reduced motion the list opens and closes at once. Without WebGL2 it is a plain frosted list.