Skip to content

Context menu

A right-click menu on Base UI ContextMenu that reuses the dropdown menu rows.

A shortcut to actions that are also reachable another way, for example in a @khaeli/dropdown-menu on the same row: nothing on screen says a context menu is there, and macOS has no key that opens one. The rows are the dropdown menu's own.

Default

Invoice 1042Right-click, long-press or press the Menu key

Checkbox radio and submenu

Review the pricing page copyNormal priority

Installation

npx shadcn@latest add @khaeli/context-menu

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0

Keyboard

Menu keyShift F10
The browser, not the item, turns these into the contextmenu event on the element that has focus, so the trigger must take focus: give it tabIndex={0}, or put a control inside it. In Chromium on macOS the Menu key opened the menu over the middle of the trigger and Shift F10 did nothing, as macOS has no such shortcut.
Arrow DownArrow Up
Focus starts on the menu. Arrow Down moves to the first row; after that the keys are the dropdown menu's.
EnterSpace
Run the row and close the menu. On a checkbox or radio row they change the value and the menu stays open.
Escape
Closes the menu and returns focus to the trigger.

Accessible name

  • The menu has no button to take a name from, so it has none until you give ContextMenuContent an aria-label.
  • ContextMenuTrigger renders a div. As a focus stop it needs a role and a name of its own: the examples use role="group" with aria-label.
  • On a touch screen a long press opens the menu.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/context-menu.json