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.
Used for
- Message actions
- Run row actions
- Canvas node actions
- File tree actions
- Right-click anywhere
Examples
Installation
npx knowns-ui@latest add context-menuFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Context menu from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/context-menu
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add context-menu
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/menu.tsx
- components/ui/knowns/context-menu/context-menu.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/context-menu, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "context-menu" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.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- Default
true - 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| childrenrequired | ReactElement | required | The region. One element that passes props and a ref to a DOM node: it is cloned with the handlers. |
| itemsrequired | MenuItem[] | MenuSection[] | required | Rows or sections, as in Menu: checked rows, danger rows, descriptions, submenus. |
| onSelectrequired | (item, event) => void | required | Called for an enabled leaf row. The menu closes unless the row keeps it open. |
| longPress | boolean | true | 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 | required | 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
- 01Opens at the pointer on right-click, and at the region on Shift+F10 or the menu key, so keyboard users get it too.
- 02Opens on a long press on touch and pen, with a short rest and a small drift allowed, so a scroll never opens it.
- 03Keeps Menu's rows: sections, checked rows, danger rows, submenus and typeahead, with the arrows and Home and End to move.
- 04Stays inside the screen: it opens toward the side with more room and never runs off an edge.
- 05Returns focus to the region on close, and hides the iOS callout that would cover the menu.
- 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
| State | What moves | Timing |
|---|---|---|
| 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
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" }).