Skip to content

Menu

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.

On this page
Used for
  • Run actions
  • Context menu on rows
  • Single-choice picker
  • Settings toggles
  • Nested commands

Examples

Installation

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

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"
Defaultcontent
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
Defaultcheckbox / 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

  1. 01Opens from the trigger you pass, cloning it with the click and key handlers, aria-haspopup, aria-expanded and aria-controls it needs.
  2. 02Moves through rows with the arrow keys, Home, End, PageUp and PageDown, skipping disabled rows, and closes on Escape or Tab.
  3. 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.
  4. 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.
  5. 05Switches to role listbox for single-choice pickers, and supports radio, checkbox and switch rows, with the last two staying open after a pick.
  6. 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

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

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" }).

Need help?

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