UI

Context menu

Contextual actions opened by right-click, long press or keyboard.

Read Markdown

Web 0.2.0

  • Defaultlight16.03 : 1AA 4.5dark4.90 : 1AA 4.5
  • KeyboardShift+F10ArrowDownArrowUpEndHomeEnterEscape
  • measured on 0.2.0
npx shadcn@latest add @maeso/context-menu
Size
54.4 kB gzipmeasured on 0.2.0

Usage

Supply a focusable trigger, a menu label and actions with stable ids. Each onSelect receives its action id; ordinary trigger clicks remain available.

Accessibility

Right-click or long-press the trigger, or focus it and press Shift+F10 or the Context Menu key. Arrows navigate; Enter selects; Escape dismisses and returns focus. Keep essential actions available through a visible control too.

When to use

Use for secondary actions on an object. Use Menu for a visible action button and Select for a form value. Empty or disabled menus stay closed.

Install

Add this registry to your project's components.json once, before the first install. Keep your existing settings and other registries.

{
  "registries": {
    "@maeso": "http://127.0.0.1:4321/r/{name}.json"
  }
}

Then install the registry's default theme once, and import its sheet in the CSS entry that imports Tailwind. It paints every item from this registry.

npx shadcn@latest add @maeso/maeso
@import "./styles/theme.web.css";
npx shadcn@latest add @maeso/context-menu

Props

ContextMenu

PropTypeRequiredDescription
itemsreadonly ContextMenuAction[]yes
labelstringyesThe accessible name of the menu.
triggerReactElement<unknown, string | JSXElementConstructor<any>>yesA focusable element; keep its ordinary click action available.
disabledboolean | undefinedno

Proof

Contrast

measured on 0.2.0

StateForegroundBackgroundRatioFloor
defaultrgb(7 21 34)rgb(239 239 239)16.03AA 4.5
default (dark)rgb(248 245 240)rgb(107 107 107)4.90AA 4.5

Keyboard

measured on 0.2.0

KeyAction
Shift+F10Open menu and focus its first item
ArrowDownFocus the next item
ArrowUpFocus the previous item
EndFocus the last item
HomeFocus the first item
EnterChoose the focused item and return focus to the trigger
EscapeDismiss the menu and return focus to the trigger

Size

54392 gzip bytes · measured on 0.2.0

Motion

The menu enters beside its trigger.

Configured duration: 200 ms

Reduced motion: none

Motion timing

Observed duration: 200 ms · measured on 0.2.0

Reduced motion

passed · measured on 0.2.0

Example

import { ContextMenu } from "@/components/ui/_kit/overlay/context-menu/ContextMenu";

export default function Example() {
return <ContextMenu label="Document actions" trigger={<button type="button">Document</button>} items={[{ id: "open", label: "Open", onSelect: () => {} }]} />;
}

not on native yet