Skip to content
Nacre
Color palette
中文

DropdownMenu

stableDropdownMenuOpen in playground
DropdownMenu
Runs the real component in your browser.

A set of actions opened from a button. Menu entries (MenuEntry) use type to tell item / heading / separator apart, and can carry an icon, a shortcut, a checkmark, a disabled state or a destructive style; the menu closes once an item is chosen.

Status: stable · Components: DropdownMenu

import { DropdownMenu } from 'nacre'

The most common case is the “More” at the end of a table row or the corner of a card: an IconButton triggers it, and its tooltip is hidden while the menu is open (tooltip={open() ? null : undefined}).

import { Text, View, signal } from 'nsh'
import { DropdownMenu, IconButton, TEXT_SIZE } from 'nacre'
export function DropdownMenuUsage() {
const last = signal('')
return (
<View class="flex-row items-center gap-3">
<DropdownMenu
trigger={(open) => <IconButton icon="more" label="Row actions" pressed={open()} expanded={open()} tooltip={open() ? null : undefined} />}
items={() => [
{ label: 'View', onSelect: () => last.set('View') },
{ label: 'Assign', onSelect: () => last.set('Assign') },
]}
/>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$Last action: ${last() || '—'}`}</Text>
</View>
)
}

heading for group titles, icon, shortcut at the end of the row, checked for a checkmark, disabled, separator for a divider, and destructive for dangerous items (placed last).

Phone: On phones rows are 44 tall and shortcut is hidden; icons, checks, disabled items, separators and destructive items work as on desktop.

import { Text, View, signal } from 'nsh'
import { Button, DropdownMenu, TEXT_SIZE } from 'nacre'
export function DropdownMenuEntries() {
const last = signal('')
const pinned = signal(true)
return (
<View class="flex-row items-center gap-3">
<DropdownMenu
align="start"
trigger={(open) => (
<Button variant="outline" icon="more" trailingIcon="chevron-down" expanded={open()} pressed={open()} tooltip={open() ? null : undefined}>
Actions
</Button>
)}
items={() => [
{ type: 'heading', label: 'Chat' },
{ label: 'Copy link', icon: 'copy', shortcut: '⌘C', onSelect: () => last.set('Copy link') },
{ label: 'Export…', icon: 'export', shortcut: '⇧⌘E', onSelect: () => last.set('Export') },
{ label: 'Pin', checked: pinned(), onSelect: () => pinned.update((v) => !v) },
{ label: 'Transfer (no permission)', icon: 'reply', disabled: true },
{ type: 'separator' },
{ label: 'Delete chat', icon: 'trash', destructive: true, onSelect: () => last.set('Delete') },
]}
/>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$Selected: ${last() || '—'}`}</Text>
</View>
)
}

items is evaluated each time the menu opens; write permission-gated items as cond && { … }, and falsy values are skipped.

import { Text, View, signal } from 'nsh'
import { Button, DropdownMenu, Switch, TEXT_SIZE } from 'nacre'
export function DropdownMenuConditional() {
const canTransfer = signal(false)
return (
<View class="flex-row flex-wrap items-center gap-3">
<DropdownMenu
align="start"
trigger={(open) => (
<Button variant="outline" trailingIcon="chevron-down" expanded={open()} pressed={open()}>
Chat actions
</Button>
)}
items={() => [
{ label: 'Mark for follow-up', icon: 'star', onSelect: () => {} },
canTransfer() && { label: 'Transfer to another agent', icon: 'reply', onSelect: () => {} },
{ type: 'separator' },
{ label: 'End chat', icon: 'close', destructive: true, onSelect: () => {} },
]}
/>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>Can transfer</Text>
<Switch checked={canTransfer()} onChange={(next) => canTransfer.set(next)} accessibilityLabel="Can transfer" />
</View>
)
}

openOnHover: the menu also opens when the pointer rests on the trigger for 150ms, for dense “More” buttons such as at the end of table rows.

Phone: Phones have no hover: openOnHover does nothing and a tap opens the menu; rows are 44 tall and shortcuts are hidden.

import { View } from 'nsh'
import { DropdownMenu, IconButton } from 'nacre'
export function DropdownMenuHover() {
return (
<DropdownMenu
openOnHover
trigger={(open) => <IconButton icon="more" label="More actions" pressed={open()} expanded={open()} tooltip={open() ? null : undefined} />}
items={() => [
{ label: 'View details', icon: 'eye', onSelect: () => {} },
{ label: 'Copy ticket number', icon: 'copy', onSelect: () => {} },
{ label: 'Close', icon: 'check', onSelect: () => {} },
]}
/>
)
}
Key Action
Space / Return On the trigger: open; on an item: choose it and close
↑ ↓ Move between selectable items (skipping headings, separators and disabled items)
Home / End Go to the first / last item
字母键 Jump to the item starting with that letter
Esc Close and return focus to the trigger
  • The trigger passes expanded, read as expanded / collapsed; an icon-only trigger is an IconButton whose label names the action (“Row actions”).
  • Checked items read as checked; plain items without onSelect read as disabled.
  • Group titles must set type: ‘heading’ explicitly; screen readers and the keyboard both skip them.

Do

  • Mark dangerous items red (destructive), put them last and add a separator before them
  • Set heading explicitly for group titles
  • Put shortcuts in shortcut, not in the label

Don’t

  • Use it to pick a value (use Select)
  • Draw your own context menu (use the system menu)
  • Tuck one or two actions into a menu (show them as buttons)

Property descriptions follow the Chinese source comments.

Prop Type Default Description
trigger * JSX.Element | ((open: () => boolean) => JSX.Element) — 触发器(一般是一枚 IconButton),按下开合。写成函数时拿到「菜单开着吗」:开着时把触发器的悬停提示收起 (NSH 不会替你收,提示会压在菜单第一行上,FINDINGS 49)。只调用一次,open 是读值函数,不会因开合重建触发器
items * () => readonly DropdownEntry[] — 菜单项,每次打开时取值;{ type: 'separator' } 是分隔线,只有 label 没有 onSelect 的是组标题
placement 'top' | 'bottom' | 'left' | 'right' 'bottom' 弹层落在触发器哪一侧,默认下
align 'start' | 'center' | 'end' 'end' 与触发器对齐,默认 end:这些菜单都在窗口右侧,靠右不出界
offset number 4
openOnHover boolean — 指针停在触发器上 150ms 也展开(表格行尾「更多」);悬停开着时再点触发器不收起

* required