Skip to content

Components

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.

Markdown
Latest changeImprovedv2.0.0Choose where it opens with over and from, close faster, and hold the trigger to open it.
  1. v2.0.0ImprovedChoose where it opens with over and from, close faster, and hold the trigger to open it.
  2. v1.0.0NewFirst release, in @vitrumui/react/dropdown-menu.
  3. All changes →
glass-dropdown-menu-basic.tsx

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/react
Peer: React 19

The 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

app.tsx
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.

toolbar.tsx
<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>
The three dots of a toolbar
glass-button-group-basic.tsx

API reference

PropTypeDefault
open / defaultOpen / onOpenChange

On GlassDropdownMenu: control the menu yourself, or let it keep its own state.

boolean / boolean / (open: boolean) => void—
GlassDropdownMenuTrigger asChild

Put the trigger on its single child (a GlassButtonGroupItem) instead of a glass button of its own.

booleanfalse
GlassDropdownMenuContent side / align

Where 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 sideOffset

The gap between the control and the list, where the neck stretches.

number12
GlassDropdownMenuItem onSelect

Runs when the item is pressed; the menu then closes (closeOnSelect={false} keeps it open).

() => void—
GlassDropdownMenuItem destructive

Paints the item red, for Delete.

booleanfalse
GlassDropdownMenuItem disabled

Dimmed and skipped by the keyboard.

booleanfalse
GlassDropdownMenuSeparator

A hairline between items.

className—

Accessibility

  • A button with aria-haspopup that opens a menu of menuitems (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.