Menu

A list of actions behind a button, for people and agents.

Source
$npx @dinachi/cli@latest add menu
MenuLabel
MenuShortcut
openOnHover
modal

Usage

import { Menu, MenuContent, MenuItem, MenuTrigger } from "@/components/ui/menu"

export function ProjectActions() {
  return (
    <Menu>
      <MenuTrigger>Actions</MenuTrigger>
      <MenuContent>
        <MenuItem onClick={() => rename()}>Rename</MenuItem>
        <MenuItem onClick={() => duplicate()}>Duplicate</MenuItem>
      </MenuContent>
    </Menu>
  )
}

Examples

Items, shortcuts and separators.
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuItem,
  MenuSeparator,
  MenuShortcut,
  MenuGroup,
  MenuLabel,
} from '@/components/ui/menu';

export function Example() {
  return (
    <Menu>
      <MenuTrigger>Open Menu</MenuTrigger>
      <MenuContent>
        <MenuGroup>
          <MenuLabel>My Account</MenuLabel>
          <MenuItem>
            Profile
            <MenuShortcut>⌘P</MenuShortcut>
          </MenuItem>
          <MenuItem>
            Settings
            <MenuShortcut>⌘S</MenuShortcut>
          </MenuItem>
          <MenuItem>
            Keyboard Shortcuts
            <MenuShortcut>⌘K</MenuShortcut>
          </MenuItem>
        </MenuGroup>
        <MenuSeparator />
        <MenuItem>Log out</MenuItem>
      </MenuContent>
    </Menu>
  );
}

Notes

Positioning

MenuContent includes its portal and positioner and passes side, align, sideOffset and alignOffset to the positioner. For anything else the positioner takes, compose MenuPortal and MenuPositioner around a popup.

Filtering

  • Wrap the menu in MenuFilter, put MenuInput at the top of the popup and the items inside MenuList. MenuEmpty shows when nothing matches.
  • A filterable submenu needs its own MenuFilter around MenuSub.
  • To separate groups, mark each data-filter-section and start it with <MenuSeparator data-filter-separator className="hidden" />. MenuList shows it only between two visible groups.
  • Filtering is a Base UI preview; its API may change.

API

openboolean
Controlled open state.
defaultOpenboolean = false
Starting open state when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs on open and close, for people and agents. details.cancel() refuses.
modalboolean = true
Locks page scroll and outside clicks while open.
loopFocusboolean = true
Wraps keyboard focus from the last item to the first.
disabledboolean = false
Ignores interaction.
orientation"vertical" | "horizontal" = "vertical"
Which arrow keys move between items.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as menu.

Reads

label

The trigger's text, or the popup's own name if set.

open

Whether the popup is showing. Closed, the agent sees the trigger; open, the popup.

Actions

open() / close()

Whichever fits the current state.

press() on an item

Items are listed inside the open menu as menuitem. Runs the item as a click.

setChecked(true) on a checkbox item

Ticks or unticks it. Radio items take only press.

Opening and closing run through onOpenChange. isAgentChange(details) is true for an agent's change, and details.cancel() refuses it; the agent is told the app refused. An item press is a click, so onClick and onCheckedChange get an ordinary event. Disabled items refuse on their own.

await agent.act({
  steps: [
    { ref: "Open Menu", action: "open" },
    { ref: "Profile", action: "press" },
  ],
})

Accessibility

  • The trigger is a button; items are menuitem, menuitemcheckbox or menuitemradio, with checked state.
  • Give an icon-only trigger an aria-label. The agent uses the same name.
  • Disabled items stay announced but are skipped by the keyboard.
  • Focus returns to the trigger when the menu closes.
  • Reduced motion drops the popup's scale and keeps the fade.