Menu
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 change Improved v3.0.9 By default the glass opens and closes at Popover's time: in place about 590 ms after the press and back in 420 ms after the close (MENU.open 0.94, close 0.56; Glass HQ's 0.42 and 0.32 took about 260 and 240, quicker than any other surface).
- v3.0.9 Improved By default the glass opens and closes at Popover's time: in place about 590 ms after the press and back in 420 ms after the close (
MENU.open0.94,close0.56; Glass HQ's 0.42 and 0.32 took about 260 and 240, quicker than any other surface). - v3.0.9 Improved A submenu grows out of the item that opened it instead of its own middle, and leaves in 100 ms (150 in).
- v2.0.2 Fixed A Menu or a Popover that was shut asked the engine for a new frame on every frame, for as long as it was on the page: the loop never stopped, and the browser went through a whole frame of its own each time with nothing moving. It now says once that it has landed, and the page is still again.
- v1.7.4 Fixed Menu: in Safari on iPhone, a thin magenta line could show down the right side of the list for a frame or two as it came into focus. The list comes out of a blur while the glass, still smaller than the list, cuts it to its own shape, and WebKit draws a blur of under about a pixel and a half on a list cut that way with that line. The blur now ends at two device pixels instead of thinning to nothing. A Dropdown Menu with
overbrings its list in the same way, and its blur ends there too. - v1.7.3 Improved Menu 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.3 Improved The 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".
- 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-svelte@latest add https://liquidglass.pulse.city/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.
Speed: the preview above has a Default / Quick switch. Quick plays Emil Kowalski's timings; the default is the speed the glass was made with. Set it on one component with tempo, or for the whole page once with setGlassTempo('quick'); the prop wins over the page. Nothing extra to install.
API reference
| Prop | Type | Default |
|---|---|---|
tempo On | 'default' | 'quick' | 'default' |
open / defaultOpen / onOpenChange On | boolean / boolean / (open: boolean) => void | — |
GlassMenuTrigger className The button is a pill 48px tall. | string | — |
GlassMenuTrigger asChild Put the trigger on its single child (a | boolean | false |
GlassMenuContent side Where the menu lies against its button. It flips when there is no room. | 'bottom' | 'top' | 'left' | 'right' | 'bottom' |
GlassMenuContent align How the menu lines up with the button along that side. | 'start' | 'center' | 'end' | 'start' |
GlassMenuContent sideOffset The gap between the button and the menu, in px. | number | 8 |
GlassMenuItem onSelect Runs when the item is pressed; the menu then closes ( | () => void | — |
GlassMenuItem destructive / disabled
| boolean | false |
GlassMenuItem shortcut The item's keys, as | string | — |
GlassMenuCheckboxItem value Names the option (required). | string | — |
GlassMenuCheckboxItem checked / defaultChecked / onCheckedChange The 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 / onValueChange The one value its | string / string / (value: string) => void | — |
GlassMenuGroup / GlassMenuLabel A set of items and its quiet heading. | children | — |
GlassMenuSeparator A hairline between items. | className | — |
GlassMenuSub / GlassMenuSubTrigger / GlassMenuSubContent A 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.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.