# GlassDropdownMenu

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

```tsx
import { ChevronDown, Copy, Pencil, Share2, Trash2 } from 'lucide-react'

import {
  GlassDropdownMenu,
  GlassDropdownMenuContent,
  GlassDropdownMenuItem,
  GlassDropdownMenuSeparator,
  GlassDropdownMenuTrigger,
} from '@/components/liquid-glass/glass-dropdown-menu'

const COLS = 13
const ROWS = 7

/** 1 around the middle of the grid, falling to 0 at its edge. */
const fade = (col: number, row: number) => {
  const distance = Math.hypot((col - (COLS - 1) / 2) / (COLS / 2), (row - (ROWS - 1) / 2) / (ROWS / 2))
  return Math.min(1, Math.max(0, (1 - distance) / 0.45))
}

// Open it: the button itself unfolds into the menu, which settles around it.
// Close it and the menu folds back into the button.
// Behind it, only the Press demo's fine grid on the page's own colour, centred on the button:
// plain DOM, every cell draws its own top and left line, fainter towards the edge.
export default function Demo() {
  return (
    <div className="relative isolate flex h-96 w-full max-w-xl items-center justify-center">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]">
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span key={i} className="relative size-10" style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}>
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassDropdownMenu over="center">
        <GlassDropdownMenuTrigger className="h-12 px-6 text-[15px]">
          Options
          <ChevronDown className="opacity-60" />
        </GlassDropdownMenuTrigger>
        <GlassDropdownMenuContent>
          <GlassDropdownMenuItem>
            <Pencil />
            Rename
          </GlassDropdownMenuItem>
          <GlassDropdownMenuItem>
            <Copy />
            Duplicate
          </GlassDropdownMenuItem>
          <GlassDropdownMenuItem>
            <Share2 />
            Share
          </GlassDropdownMenuItem>
          <GlassDropdownMenuSeparator />
          <GlassDropdownMenuItem destructive>
            <Trash2 />
            Delete
          </GlassDropdownMenuItem>
        </GlassDropdownMenuContent>
      </GlassDropdownMenu>
    </div>
  )
}
```

**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.

```bash
npx shadcn@latest add https://onemorethink.dev/r/dropdown-menu.json
```

> 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

```tsx
import {
  GlassDropdownMenu,
  GlassDropdownMenuContent,
  GlassDropdownMenuItem,
  GlassDropdownMenuSeparator,
  GlassDropdownMenuTrigger,
} from '@/components/liquid-glass/glass-dropdown-menu'

<GlassDropdownMenu over="center">
  <GlassDropdownMenuTrigger>Options</GlassDropdownMenuTrigger>
  <GlassDropdownMenuContent>
    <GlassDropdownMenuItem onSelect={rename}>Rename</GlassDropdownMenuItem>
    <GlassDropdownMenuItem onSelect={duplicate}>Duplicate</GlassDropdownMenuItem>
    <GlassDropdownMenuSeparator />
    <GlassDropdownMenuItem destructive onSelect={remove}>Delete</GlassDropdownMenuItem>
  </GlassDropdownMenuContent>
</GlassDropdownMenu>
```

With `over="center"` on `GlassDropdownMenu`, the button itself unfolds into the menu, which settles around it with the button in its middle: Popover's opening. `over="edge"` grows it from the button's own edge instead, and `from="bottom"` brings it up from below where it comes down from above by default. Closing folds it back into the button. The menu stays where it is instead of flipping, so keep the button away from the top and bottom of the screen. The trigger wears Button's clear glass, so it needs something behind it to bend.

## Opening on a neck

Leave `over` out for Select's motion: 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. It flips when there is no room.

### A list that stretches out of its button

```tsx
import { ChevronDown, Copy, Pencil, Share2, Trash2 } from 'lucide-react'

import {
  GlassDropdownMenu,
  GlassDropdownMenuContent,
  GlassDropdownMenuItem,
  GlassDropdownMenuSeparator,
  GlassDropdownMenuTrigger,
} from '@/components/liquid-glass/glass-dropdown-menu'

const COLS = 13
const ROWS = 7

/** 1 around the middle of the grid, falling to 0 at its edge. */
const fade = (col: number, row: number) => {
  const distance = Math.hypot((col - (COLS - 1) / 2) / (COLS / 2), (row - (ROWS - 1) / 2) / (ROWS / 2))
  return Math.min(1, Math.max(0, (1 - distance) / 0.45))
}

// Without `over`: the list swells out of the whole button, a neck stretches between them and
// snaps, and the actions arrive one by one. Close it and the same motion plays backwards.
export default function Demo() {
  return (
    <div className="relative isolate flex h-96 w-full max-w-xl items-center justify-center">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]">
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span key={i} className="relative size-10" style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}>
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassDropdownMenu>
        <GlassDropdownMenuTrigger className="h-12 px-6 text-[15px]">
          Actions
          <ChevronDown className="opacity-60" />
        </GlassDropdownMenuTrigger>
        <GlassDropdownMenuContent>
          <GlassDropdownMenuItem>
            <Pencil />
            Rename
          </GlassDropdownMenuItem>
          <GlassDropdownMenuItem>
            <Copy />
            Duplicate
          </GlassDropdownMenuItem>
          <GlassDropdownMenuItem>
            <Share2 />
            Share
          </GlassDropdownMenuItem>
          <GlassDropdownMenuSeparator />
          <GlassDropdownMenuItem destructive>
            <Trash2 />
            Delete
          </GlassDropdownMenuItem>
        </GlassDropdownMenuContent>
      </GlassDropdownMenu>
    </div>
  )
}
```

## 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 menu comes out of its body and takes its colour, white included. Wrap only the group that opens the menu.

```tsx
<GlassDropdownMenu over="center">
  <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

```tsx
import { Archive, ArrowLeft, BellOff, Clock, Ellipsis, Flag, MailOpen, Tag, Trash2 } from 'lucide-react'

import { GlassButtonGroup, GlassButtonGroupItem } from '@/components/liquid-glass'
import {
  GlassDropdownMenu,
  GlassDropdownMenuContent,
  GlassDropdownMenuItem,
  GlassDropdownMenuSeparator,
  GlassDropdownMenuTrigger,
} from '@/components/liquid-glass/glass-dropdown-menu'

const COLS = 13
const ROWS = 7

/** 1 around the middle of the grid, falling to 0 at its edge. */
const fade = (col: number, row: number) => {
  const distance = Math.hypot((col - (COLS - 1) / 2) / (COLS / 2), (row - (ROWS - 1) / 2) / (ROWS / 2))
  return Math.min(1, Math.max(0, (1 - distance) / 0.45))
}

// The actions of a message. Some share a body of glass, some stand apart: nested groups, with
// the outer one only spacing them. The glass is white unless a group brings its own colour,
// as the back button does. Snooze stands apart in clear glass (`material="clear"`): it bends the
// grid, and its rim mirrors the white glass beside it. The three dots stand apart and unfold
// into a menu that settles around them.
// Where the row would not fit (a phone), the labels step aside and the icons carry it.
// Point at a body and it swells; press and it grows. Behind them, the Press demo's fine grid
// on the page's own colour, centred on the glass: plain DOM, every cell draws its own top
// and left line, fainter towards the edge.
export default function Demo() {
  return (
    <div className="@container relative isolate flex h-72 w-full max-w-xl items-center justify-center">
      <div aria-hidden className="absolute top-1/2 left-1/2 -z-10 grid -translate-x-1/2 -translate-y-1/2 grid-cols-[repeat(13,40px)]">
        {Array.from({ length: COLS * ROWS }, (_, i) => (
          <span key={i} className="relative size-10" style={{ opacity: fade(i % COLS, Math.floor(i / COLS)) }}>
            <span className="absolute inset-x-0 top-0 h-px bg-black/10 dark:bg-white/10" />
            <span className="absolute inset-y-0 left-0 w-px bg-black/10 dark:bg-white/10" />
          </span>
        ))}
      </div>
      <GlassButtonGroup aria-label="Message">
        <GlassButtonGroup className="bg-neutral-900 text-white">
          <GlassButtonGroupItem aria-label="Back" className="px-0">
            <ArrowLeft />
          </GlassButtonGroupItem>
        </GlassButtonGroup>
        <GlassButtonGroup>
          <GlassButtonGroupItem className="@max-[440px]:px-0">
            <Archive />
            <span className="@max-[440px]:sr-only">Archive</span>
          </GlassButtonGroupItem>
          <GlassButtonGroupItem className="@max-[440px]:px-0">
            <Flag />
            <span className="@max-[440px]:sr-only">Report</span>
          </GlassButtonGroupItem>
        </GlassButtonGroup>
        <GlassButtonGroup material="clear">
          <GlassButtonGroupItem className="@max-[440px]:px-0">
            <Clock />
            <span className="@max-[440px]:sr-only">Snooze</span>
          </GlassButtonGroupItem>
        </GlassButtonGroup>
        <GlassDropdownMenu over="center">
          <GlassButtonGroup>
            <GlassDropdownMenuTrigger asChild>
              <GlassButtonGroupItem aria-label="More" className="px-0">
                <Ellipsis />
              </GlassButtonGroupItem>
            </GlassDropdownMenuTrigger>
          </GlassButtonGroup>
          <GlassDropdownMenuContent>
            <GlassDropdownMenuItem>
              <MailOpen />
              Mark as read
            </GlassDropdownMenuItem>
            <GlassDropdownMenuItem>
              <Tag />
              Add label
            </GlassDropdownMenuItem>
            <GlassDropdownMenuItem>
              <BellOff />
              Mute thread
            </GlassDropdownMenuItem>
            <GlassDropdownMenuSeparator />
            <GlassDropdownMenuItem destructive>
              <Trash2 />
              Delete
            </GlassDropdownMenuItem>
          </GlassDropdownMenuContent>
        </GlassDropdownMenu>
      </GlassButtonGroup>
    </div>
  )
}
```

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open / defaultOpen / onOpenChange` | `boolean / boolean / (open: boolean) => void` | — | On `GlassDropdownMenu`: control the menu yourself, or let it keep its own state. |
| `over` | `'center' \| 'edge'` | — | On `GlassDropdownMenu`: the button unfolds into the menu. `center`: the menu settles around it. `edge`: it grows from the button's own edge, away from it. Left out, the list swells out of the control on a neck. |
| `from` | `'top' \| 'bottom'` | `'top'` | On `GlassDropdownMenu`, with `over`: which way the menu comes into place. `top`: the button is thrown down and the menu comes down from above. `bottom`: the other way up. |
| `GlassDropdownMenuTrigger asChild` | `boolean` | `false` | Put the trigger on its single child (a `GlassButtonGroupItem`) instead of a glass button of its own. |
| `GlassDropdownMenuContent side / align` | `'top' \| 'bottom' / 'start' \| 'center' \| 'end'` | `'bottom' / 'center'` | Where the list opens against the trigger: below and centred by default. It flips when there is no room. |
| `GlassDropdownMenuContent sideOffset` | `number` | `12` | The gap between the control and the list, where the neck stretches. With `over="center"`, passing it places the menu yourself. |
| `GlassDropdownMenuItem onSelect` | `() => void` | — | Runs when the item is pressed; the menu then closes (`closeOnSelect={false}` keeps it open). |
| `GlassDropdownMenuItem destructive` | `boolean` | `false` | Paints the item red, for Delete. |
| `GlassDropdownMenuItem disabled` | `boolean` | `false` | Dimmed and skipped by the keyboard. |
| `GlassDropdownMenuSeparator` | `className` | — | A hairline between items. |

## Accessibility

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

Source: https://onemorethink.dev/docs/dropdown-menu
