MenuNew
A menu its button grows into: the button's own glass pours towards where the menu lies, below, above or beside it, and runs the same way back. With submenus, checkbox and radio items, groups and shortcuts.
Latest changeImprovedv1.7.3Menu opens out of a button group: GlassMenuTrigger asChild puts the trigger on an item of a GlassButtonGroup, and the whole group's glass grows into the menu. The three dots of the Button Group example are now a Menu.
- v1.7.3ImprovedMenu opens out of a button group:
GlassMenuTrigger asChildputs the trigger on an item of a GlassButtonGroup, and the whole group's glass grows into the menu. The three dots of the Button Group example are now a Menu. - v1.7.3ImprovedThe Menu page and its tile on the landing page now open with the menu button itself: the three dots that grow into a menu with a submenu. The four buttons that open to four sides moved down to "On any side".
- v1.7.3FixedMenu, Select, Dropdown Menu and Popover: while the glass was on its way out of its control or back in, a thin dark line could show across it at the edge of the control, and the control's own box could look lighter than the rest. The glass is drawn there by two canvases, the control's and the surface's, that meet at the control's edge: each was cut at the same line, so both were half drawn along it and the page showed through, and the light of the press lit the control's side alone. The control's canvas now reaches a pixel under the surface's, and the surface's takes the same light.
- v1.7.0NewMenu: a menu its button grows into. The button's own glass pours towards where the menu lies (below, above or beside it), the edge that faces the menu ahead of the rest, and runs the same way back to close; a close turned round half way carries on from where it is. It comes with submenus, checkbox and radio items, groups with a label and shortcuts. Keyboard, typeahead, focus, positioning and ARIA come from UI SDK. The motion is that of Glass HQ's liquid-glass (MIT), ported onto the kit's own engine.
- v1.7.0Improved
GlassPopuphas a third way out:useGlassPopup({ opening: 'grow' })grows a control's glass into the surface it opens, wherever that surface lies. One shape on one spring, drawn by one canvas once the label has gone, and the page behind is read once per opening. Its numbers areMENUinengine.ts. Select, Dropdown Menu and Popover keep their own motion. - All changes →
Use it for
- A menu with structure: options that stay checked, one choice among a few, groups with a label, a submenu.
- A menu that must open to one side: above a bottom bar, beside a sidebar row.
- The three dots of a card or a row: a small round button that becomes its menu.
Not for
- A few plain actions out of a button or a Button Group: use Dropdown Menu.
- Picking a value that stays shown on the control: use Select.
- A short form or a note about one control: use Popover.
Installation
npx shadcn@latest add https://onemorethink.dev/r/menu.jsonThe behaviour (keyboard, typeahead, focus, submenus, positioning, ARIA) comes from UI SDK, so 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 {
GlassMenu,
GlassMenuContent,
GlassMenuItem,
GlassMenuSeparator,
GlassMenuTrigger,
} from '@/components/liquid-glass/glass-menu'
<GlassMenu>
<GlassMenuTrigger aria-label="More" className="w-12 px-0"><Ellipsis /></GlassMenuTrigger>
<GlassMenuContent align="end">
<GlassMenuItem onSelect={save}>Save to library</GlassMenuItem>
<GlassMenuItem onSelect={share}>Share</GlassMenuItem>
<GlassMenuSeparator />
<GlassMenuItem destructive onSelect={remove}>Delete</GlassMenuItem>
</GlassMenuContent>
</GlassMenu>The button's glass is the menu. Pressed, its outline grows into the menu's on one spring: the edge that faces the menu runs ahead and the rest follows, so the glass pours towards its place instead of scaling up. The button's label softens and goes as the glass leaves it, and the items stay where they are while the glass opens over them. While the menu is out the button is not there: it has become the menu. Closing runs the same path back, and a close turned round half way carries on from where it is, at the speed it has. The trigger wears Button's clear glass, so it needs something behind it to bend.
On any side
side on GlassMenuContent says where the menu lies (bottom, top, left, right) and align how it lines up with the button (start, center, end). The glass finds its own way there, and the menu flips to the other side when there is no room.
Options, groups and shortcuts
GlassMenuCheckboxItem is an option that stays on or off, and GlassMenuRadioItems in a GlassMenuRadioGroup share one value. Both keep the menu open, so several can be set in one visit. GlassMenuGroup with a GlassMenuLabel names a set of items. An item with a shortcut shows its keys through GlassMenuShortcut.
Submenus
Put a GlassMenuSub among the items, with a GlassMenuSubTrigger and a GlassMenuSubContent inside. The row opens its submenu on hover, on a press and with the arrow key; the submenu is a card of the same glass that fades in beside its row. The menu at the top of the page has one.
<GlassMenuContent>
<GlassMenuItem>Share</GlassMenuItem>
<GlassMenuSub>
<GlassMenuSubTrigger>Move to</GlassMenuSubTrigger>
<GlassMenuSubContent>
<GlassMenuItem>Favourites</GlassMenuItem>
<GlassMenuItem>Archive</GlassMenuItem>
</GlassMenuSubContent>
</GlassMenuSub>
</GlassMenuContent>Out of a button group
Wrap a GlassButtonGroup and the content in the menu, and put the trigger on one of the group's items with asChild. The whole group's glass is then the one that grows into the menu, and the menu takes its colour.
<GlassMenu>
<GlassButtonGroup>
<GlassMenuTrigger asChild>
<GlassButtonGroupItem aria-label="More" className="px-0"><Ellipsis /></GlassButtonGroupItem>
</GlassMenuTrigger>
</GlassButtonGroup>
<GlassMenuContent align="end">
<GlassMenuItem>Mark as read</GlassMenuItem>
<GlassMenuItem destructive>Delete</GlassMenuItem>
</GlassMenuContent>
</GlassMenu>The motion on your own popup
Menu is built on GlassPopup: useGlassPopup({ opening: 'grow' }) gives any control that opens a surface the same motion, with GlassPopupAnchor as the control's first child and GlassPopupSurface as the content's. Wrap the content's children in an element with data-glass-list. The numbers (the spring, which side leads, when the label goes and the content shows) are MENU in engine.ts.
API reference
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeOn | boolean / boolean / (open: boolean) => void | — |
GlassMenuTrigger classNameThe button is a pill 48px tall. | string | — |
GlassMenuTrigger asChildPut the trigger on its single child (a | boolean | false |
GlassMenuContent sideWhere the menu lies against its button. It flips when there is no room. | 'bottom' | 'top' | 'left' | 'right' | 'bottom' |
GlassMenuContent alignHow the menu lines up with the button along that side. | 'start' | 'center' | 'end' | 'start' |
GlassMenuContent sideOffsetThe gap between the button and the menu, in px. | number | 8 |
GlassMenuItem onSelectRuns when the item is pressed; the menu then closes ( | () => void | — |
GlassMenuItem destructive / disabled
| boolean | false |
GlassMenuItem shortcutThe item's keys, as | string | — |
GlassMenuCheckboxItem valueNames the option (required). | string | — |
GlassMenuCheckboxItem checked / defaultChecked / onCheckedChangeThe option's state, yours or its own. A check shows at its end while it is on. | boolean / boolean / (checked: boolean) => void | — |
GlassMenuRadioGroup value / defaultValue / onValueChangeThe one value its | string / string / (value: string) => void | — |
GlassMenuGroup / GlassMenuLabelA set of items and its quiet heading. | children | — |
GlassMenuSeparatorA hairline between items. | className | — |
GlassMenuSub / GlassMenuSubTrigger / GlassMenuSubContentA submenu, the row that opens it and its card. | children | — |
Accessibility
- A button with
aria-haspopupthat opens amenuofmenuitem,menuitemcheckboxandmenuitemradiorows (the WAI-ARIA menu button pattern). - Arrow keys, Home and End move through the items, typing a letter jumps to a match, Enter or Space runs the item. The right arrow opens a submenu and the left arrow closes it. Escape closes the menu and returns focus to the button.
- The button is hidden while the menu is out, and still there for the keyboard and for screen readers: focus returns to it on close.
- An icon-only button needs an
aria-label. - With reduced motion the menu opens and closes at once. Without WebGL2 it is a plain frosted list.