Rime

ContextMenu

A menu of actions for a region, opened at the pointer with a right-click, Shift+F10 or a long press.

ContextMenu wraps a region (a row, a card, a file) and opens the shared menu list where the pointer is. The region is focusable, so keyboard users open it with Shift+F10 or the Menu key; on touch a long press (longPressMs, 500ms) opens it.

Items take an icon, a shortcut hint (display only), a danger tone and a disabled state; separators and headings group them. It is the same popover glass and item rhythm as Menu.

inline renders the open panel in the page flow: no portal, scrim, focus trap, scroll lock or outside-click listener. It exists for docs, previews and static mock-ups; never ship it as the live overlay.

Installation

npx shadcn@latest add KezLahd/rime/context-menu

Also installs: base.

Usage

import { ContextMenu } from "@/components/ui";

<ContextMenu label="Actions for Invoice INV-0042" items={[
  { id: "open", label: "Open", onSelect: open },
  { id: "rename", label: "Rename", shortcut: "F2", onSelect: rename },
  { id: "sep", separator: true },
  { id: "delete", label: "Move to bin", tone: "danger", onSelect: remove },
]}>
  Invoice INV-0042.pdf
</ContextMenu>

Examples

Open

The menu over its region, drawn inline with one item highlighted.

On a region

Right-click it, or focus it and press Shift F10.

API

Generated from the component's TypeScript types and JSDoc (scripts/gen-ui-registry.mjs), so it always matches the source.

ContextMenu

ContextMenu props
PropTypeDefaultDescription
childrenRequiredReactNodeThe region that answers a right-click: a row, a card, a canvas.
itemsRequiredReadonlyArray<MenuListEntry>The menu: actions, separators ({ id, separator: true }) and headings ({ id, heading }).
labelRequiredstringThe menu's accessible name, e.g. "Actions for Invoice INV-0042".
longPressMsnumber500ms a touch must be held to open it on phones and tablets.
inlinebooleanRender the menu open in the page flow, over the region (docs, previews). Nothing is interactive and no listeners are attached.
highlightIdstringInline only: the item drawn in its hover state.
classNamestring

Theme tokens

Per-component tokens are undeclared by default, so the default shown is the fallback the CSS uses. Set one at :root (or in theme.css) to restyle every instance. Live values are read from this page, so they follow the Rime Studio.

ContextMenu per-component tokens
TokenDefaultLive value
--context-region-height150px…
--context-region-radiusvar(--r-lg)…
--context-region-width300px…
--menu-list-min-width220px…
--popover-item-active-bglinear-gradient(to right, rgba(var(--rgb-brand), 0.14), rgba(var(--rgb-brand-deep), 0.07))…
--popover-item-press-bglinear-gradient(to right, rgba(var(--rgb-brand), 0.2), rgba(var(--rgb-brand-deep), 0.1))…
--popover-item-radiusvar(--r-xs)…
--popover-padcalc(6px * var(--density))…
--popover-radiusvar(--r-lg)…

System tokens it reads

ContextMenu system tokens
TokenDefaultLive value
--border-wtokens.css…
--danger-inktokens.css…
--densitytokens.css…
--durtokens.css…
--dur-fasttokens.css…
--dur-slowtokens.css…
--easetokens.css…
--ease-outtokens.css…
--focus-ringtokens.css…
--font-bodytokens.css…
--ink-bodytokens.css…
--ink-brandtokens.css…
--ink-disabledtokens.css…
--ink-mutedtokens.css…
--line-inputtokens.css…
--line-softtokens.css…
--popover-blurtokens.css…
--popover-bordertokens.css…
--popover-shadowtokens.css…
--popover-surfacetokens.css…
--r-lgtokens.css…
--r-xstokens.css…
--rgb-brandtokens.css…
--rgb-brand-deeptokens.css…
--rgb-dangertokens.css…
--rgb-whitetokens.css…
--text-captiontokens.css…
--text-microtokens.css…
--text-smalltokens.css…
--tracking-labeltokens.css…
--wash-subtletokens.css…
--z-popovertokens.css…

Accessibility

  • The menu is role="menu" with role="menuitem" items: arrows, Home, End and typeahead move; Enter or Space runs; Esc closes and returns focus to the region; Tab closes.
  • The region is focusable and opens on Shift+F10 and the Menu key, so a mouse is never required.
  • Every action in a context menu must also be reachable some other way (a row Menu, a toolbar).

Do and don't

Do

  • Put destructive items last, after a separator.
  • Keep it to the actions for that one thing.

Don't

  • Don't make it the only route to an action.
  • Don't override the browser's menu on text people need to copy.

For AI agents

This page as markdown, rendered from the same registry entry. Point an agent at it (or add .md to this page's URL), or at /llms.txt for the index.

Open context-menu.md

Related: menu, menubar