Actions and choices that drop from a trigger or open on right-click: sections, shortcuts, single choice, multi-select, switch rows, links and submenus - all by keyboard.
Used for
- Run actions
- Context menu on rows
- Single-choice picker
- Settings toggles
- Nested commands
Examples
Installation
npx knowns-ui@latest add 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 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/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 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
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/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: "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
- trigger
ReactElement- One element, usually a Button. Gets onClick, onKeyDown, aria-haspopup, aria-expanded, aria-controls and a ref. Enter, Space or ↓ opens at the checked or first row, ↑ at the last.
- items
MenuItem[]|MenuSection[]- A flat list, or sections with an optional small label and a hairline between them.
- onSelect
(item, event) => void- Called for enabled leaf rows (rows with submenus open them instead). Closes the whole menu unless the row keeps it open. For links, event.preventDefault() cancels the navigation.
- role
"menu"|"listbox"- Default
"menu" - Use listbox for single-choice pickers: rows become options with aria-selected. Submenus need menu.
- openOn
"click"|"contextmenu"- Default
"click" - contextmenu: right-click on the trigger, or Shift+F10 when it has focus, opens the menu at the pointer. Give the trigger tabIndex={0}.
- align / side
"start"|"end" / "top"|"bottom"|"auto"- Default
"start" / "auto" - Auto opens toward the side with more room. Panels stay 8px inside the viewport and follow scroll and resize. Submenus open to the right and flip left.
- width
number|"trigger"- Default
content - Content width between 200 and 320px by default.
- header / footer
ReactNode- Fixed content above / below the scrolling rows.
- className
string- Extra classes on every panel, the root and its submenus.
- open / onOpenChange
boolean / (open) => void- Optional control. Escape, Tab, picking and clicking outside all close it.
| Prop | Type | Default | Description |
|---|---|---|---|
| trigger | ReactElement | - | One element, usually a Button. Gets onClick, onKeyDown, aria-haspopup, aria-expanded, aria-controls and a ref. Enter, Space or ↓ opens at the checked or first row, ↑ at the last. |
| items | MenuItem[] | MenuSection[] | - | A flat list, or sections with an optional small label and a hairline between them. |
| onSelect | (item, event) => void | - | Called for enabled leaf rows (rows with submenus open them instead). Closes the whole menu unless the row keeps it open. For links, event.preventDefault() cancels the navigation. |
| role | "menu" | "listbox" | "menu" | Use listbox for single-choice pickers: rows become options with aria-selected. Submenus need menu. |
| openOn | "click" | "contextmenu" | "click" | contextmenu: right-click on the trigger, or Shift+F10 when it has focus, opens the menu at the pointer. Give the trigger tabIndex={0}. |
| align / side | "start" | "end" / "top" | "bottom" | "auto" | "start" / "auto" | Auto opens toward the side with more room. Panels stay 8px inside the viewport and follow scroll and resize. Submenus open to the right and flip left. |
| width | number | "trigger" | content | Content width between 200 and 320px by default. |
| header / footer | ReactNode | - | Fixed content above / below the scrolling rows. |
| className | string | - | Extra classes on every panel, the root and its submenus. |
| open / onOpenChange | boolean / (open) => void | - | Optional control. Escape, Tab, picking and clicking outside all close it. |
- id / label
string / ReactNode- label is the row text; give textValue when it is not a string, for typeahead.
- description / icon
ReactNode- A muted second line; a 16px box on the left.
- shortcut / trailing
string / ReactNode- Right-aligned: muted shortcut text, then any extra (a Badge, a count, ↗).
- kind
"item"|"radio"|"checkbox"|"switch"- Default
"item" - radio / checkbox show a check mark when checked (only those rows reserve its column). switch draws a small switch and is a menuitemcheckbox.
- checked
boolean- For radio, checkbox and switch rows.
- keepOpen
boolean- Default
checkbox / switch - Keep the menu open after picking this row.
- href / target
string- Render a real <a role="menuitem">: cmd/ctrl/middle-click and the browser context menu work. target="_blank" adds rel="noopener noreferrer".
- items
MenuItem[]|MenuSection[]- A submenu: the row shows ›. → / Enter / Space open it and move into it, ← / Escape close it, hovering opens it after a short delay and a diagonal move toward it keeps it open.
- disabled / danger
boolean- Skipped by the keyboard / red text for destructive rows.
- data-kind
attribute- Every row carries data-kind ("item", "link", "radio", "checkbox", "switch", "submenu") for styling.
| Prop | Type | Default | Description |
|---|---|---|---|
| id / label | string / ReactNode | - | label is the row text; give textValue when it is not a string, for typeahead. |
| description / icon | ReactNode | - | A muted second line; a 16px box on the left. |
| shortcut / trailing | string / ReactNode | - | Right-aligned: muted shortcut text, then any extra (a Badge, a count, ↗). |
| kind | "item" | "radio" | "checkbox" | "switch" | "item" | radio / checkbox show a check mark when checked (only those rows reserve its column). switch draws a small switch and is a menuitemcheckbox. |
| checked | boolean | - | For radio, checkbox and switch rows. |
| keepOpen | boolean | checkbox / switch | Keep the menu open after picking this row. |
| href / target | string | - | Render a real <a role="menuitem">: cmd/ctrl/middle-click and the browser context menu work. target="_blank" adds rel="noopener noreferrer". |
| items | MenuItem[] | MenuSection[] | - | A submenu: the row shows ›. → / Enter / Space open it and move into it, ← / Escape close it, hovering opens it after a short delay and a diagonal move toward it keeps it open. |
| disabled / danger | boolean | - | Skipped by the keyboard / red text for destructive rows. |
| data-kind | attribute | - | Every row carries data-kind ("item", "link", "radio", "checkbox", "switch", "submenu") for styling. |
What it handles
- 01Opens from the trigger you pass, cloning it with the click and key handlers, aria-haspopup, aria-expanded and aria-controls it needs.
- 02Moves through rows with the arrow keys, Home, End, PageUp and PageDown, skipping disabled rows, and closes on Escape or Tab.
- 03Jumps to a row as you type: the typed text matches the start of a label, and the query resets after 500ms without a key.
- 04Opens a submenu with ArrowRight or after a 100ms hover, closes it with ArrowLeft, and keeps a grace area so a diagonal move toward it does not close it.
- 05Switches to role listbox for single-choice pickers, and supports radio, checkbox and switch rows, with the last two staying open after a pick.
- 06Opens at the pointer with openOn contextmenu on a right-click or Shift+F10, and flips to the side with more room while staying 8px inside the viewport.
States
- First render
- Nothing. The panel is not mounted until it opens
- none
- Open
- The panel fades in with no travel
- 120ms, opacity only
- Active row
- The highlight is placed on the row at once and does not glide
- none, at once
- Submenu
- A submenu appears and disappears at once on hover or arrow keys
- none, at once
- Switch row
- The thumb slides and the track recolours
- 120ms, ease out
- Reduced motion
- The panel appears at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The panel is not mounted until it opens | none |
| Open | The panel fades in with no travel | 120ms, opacity only |
| Active row | The highlight is placed on the row at once and does not glide | none, at once |
| Submenu | A submenu appears and disappears at once on hover or arrow keys | none, at once |
| Switch row | The thumb slides and the track recolours | 120ms, ease out |
| Reduced motion | The panel appears at once | 0ms |
Works with
When to use
When to use
- A list of actions behind a button, with sections, checkable items, typeahead and arrow keys.
When not to use
- Search across the whole app: use Command Menu.
- Picking a value with search: use Combobox.
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 Menu to my app and wire it to my own data.
- I need a list of actions behind a button, with sections, checkable items, typeahead and arrow keys. Set that up with the Knowns UI Menu.
- Which Menu props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "menu" }) and search_docs({ query: "menu" }).