Skip to content

Context Menu

The menu under the pointer. Right-click, the keyboard menu key, or a long press on touch opens the same rows a Dropdown has, at the spot you pointed.

On this page
Used for
  • Message actions
  • Run row actions
  • Canvas node actions
  • File tree actions
  • Right-click anywhere

Examples

Installation

npx knowns-ui@latest add context-menu
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

childrenrequired
ReactElement
The region. One element that passes props and a ref to a DOM node: it is cloned with the handlers.
itemsrequired
MenuItem[] | MenuSection[]
Rows or sections, as in Menu: checked rows, danger rows, descriptions, submenus.
onSelectrequired
(item, event) => void
Called for an enabled leaf row. The menu closes unless the row keeps it open.
longPress
boolean
Defaulttrue
Open on a long press of 500ms for touch and pen. A drift over 8px counts as a scroll.
open / onOpenChange
boolean / (open) => void
Control it from outside.
aria-labelrequired
string
Names the menu for screen readers.
Keyboard
-
Shift+F10 or the menu key opens, arrows move, Enter picks, Escape closes and returns focus.
Motion
120ms ease-out
Fade only, like Menu. Frequent keyboard use never moves.

What it handles

  1. 01Opens at the pointer on right-click, and at the region on Shift+F10 or the menu key, so keyboard users get it too.
  2. 02Opens on a long press on touch and pen, with a short rest and a small drift allowed, so a scroll never opens it.
  3. 03Keeps Menu's rows: sections, checked rows, danger rows, submenus and typeahead, with the arrows and Home and End to move.
  4. 04Stays inside the screen: it opens toward the side with more room and never runs off an edge.
  5. 05Returns focus to the region on close, and hides the iOS callout that would cover the menu.
  6. 06Hands you the picked row through onSelect, so one handler can run every action.

States

First render
Nothing. The region paints as it is
none
Open
The panel fades in at the pointer
120ms, ease out
Close
The panel fades out
about 140ms, ease out
Row hover or arrow
The highlight glides to the row
120ms, ease out
Reduced motion
The panel appears and goes at once
0ms

Works with

When to use

When to use

  • Actions on a thing the user points at: a message, a run row, a node on a canvas, a file.

When not to use

  • Actions from a button: use Dropdown.
  • The only way to reach an action: add a visible button too, since right-click is easy to miss: use Menu.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Context Menu to my app and wire it to my own data.
  • I need actions on a thing the user points at: a message, a run row, a node on a canvas, a file. Set that up with the Knowns UI Context Menu.
  • Which Context Menu props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "context-menu" }) and search_docs({ query: "context menu" }).

Need help?

Stuck on Context Menu, or found something off? We read every message.