Accessible React action and context menus with nested submenus, native links and keyboard navigation.
The v1 public contract supports React 19 with nonmodal menus by default and optional modal interaction. See the v1 source compatibility notes when upgrading from 0.x.
Requires React 19, React DOM 19, and Tailwind CSS 4. The library has no additional runtime UI dependencies.
npm install @rentnerkev/menu
# or with Bun
bun add @rentnerkev/menuImport the package styles after Tailwind in your app stylesheet:
@import 'tailwindcss';
@import '@rentnerkev/menu/tailwind.css';'use client'
import { Menu, ContextMenu, type MenuItem } from '@rentnerkev/menu'
const items: readonly MenuItem[] = [
{ id: 'open', label: 'Open' },
{
id: 'export',
type: 'submenu',
label: 'Export',
items: [
{ id: 'json', label: 'As JSON' },
{ id: 'text', label: 'As text' },
],
},
{ id: 'separator', type: 'separator' },
{ id: 'delete', label: 'Delete', danger: true },
]
export function FileActions() {
return (
<>
<Menu
ariaLabel="File actions"
trigger="Actions"
items={items}
onAction={(id) => console.log(id)}
/>
<ContextMenu
ariaLabel="File context menu"
items={items}
onAction={(id) => console.log(id)}
>
<p>Right-click this file or press Shift+F10.</p>
</ContextMenu>
</>
)
}trigger supplies the contents of the native button rendered by Menu. Pass button attributes and handlers through triggerProps; do not nest another button inside it. With asChild, pass one button element instead; custom components must forward the injected props and ref to a native button.
Action menus execute commands. Value selection in a form remains the responsibility of @rentnerkev/select.
Package overview · Online documentation · Repository usage guide · Local playground · MIT license
Run the playground from the repository root:
bun install --frozen-lockfile
bun run playground:install
bun run playground:devOpen http://127.0.0.1:4178. The page contains compact menu examples and the last triggered action. Controlled state, RTL, viewport collisions, disabled items and the native-dialog integration test are under Weitere Tests. Kontextmenü-Tests demonstrates shared dropdown/context positioning defaults, native target actions and independent styling slots.
- Action and context menus share one typed item model.
- Nested submenus open with the pointer or direction-aware keyboard navigation; pointer corridors preserve diagonal paths into a submenu.
- Native link items with
href,target,relanddownload; selection cancellation preserves application control. - Checkbox items including
checked: 'indeterminate', radio items, labels, separators, disabled and destructive actions. - Icons, descriptions and shortcut hints. Hints do not register global hotkeys.
- Controlled or uncontrolled open state, custom button triggers with
asChild, shared providers and slotclassNames. - Opt-in mouse hover opening with configurable delays, no initial focus transfer and preserved click, touch and keyboard interaction.
- Optional
modalinteraction blocks background input and scrolling, then restores prior background attributes and scroll styles. - Shared
--rentner-*theme tokens, explicit portal containers and focus restoration. - Arrow keys, Home/End, repeated-character typeahead, Enter/Space, repeated Escape through submenu levels and Tab.
Online entry points are available as the AI package guide, the JSON package API, and the remote MCP endpoint. The remote MCP service provides hosted package documentation to connected clients; it is separate from the local helpers below. Online information can describe a different version from the one installed in your project.
The separate @rentnerkev/menu/ai entry is for Node.js and Bun tooling. It reads
this installed package's manifest, README, usage guide and built TypeScript
declarations without importing React, mounting UI or performing network requests.
Keep it out of browser code.
import {
getPackageInfo,
getPackageApi,
getPackageDocumentation,
searchPackageDocumentation,
getPackageExamples,
} from '@rentnerkev/menu/ai'
const info = getPackageInfo()
const api = getPackageApi({ symbol: 'Menu' })
const usage = getPackageDocumentation('usage')
const readme = getPackageDocumentation('readme')
const matches = searchPackageDocumentation('portal')
const examples = getPackageExamples()Unknown public subpaths or symbols throw an error. Callers cannot supply file
paths. The ./ai entry is excluded from the UI declaration context. Use the
documentation for the installed version.
Requires Bun 1.4.4 with native bun fmt support.
bun run typecheck
bun run lint
bun run format:check
bun test
bun run build
bun run pack:consumer
bun run playground:build
bunx playwright install chromium firefox webkit
bun run e2ebun run verify runs the complete checks after browser installation. Library
components, hooks and types live under src/shared/Menu, UI-free logic under
src/lib/Menu, and tests mirror these modules in src/tests. The playground is
excluded from the published package.
Publishing a stable GitHub release named vMAJOR.MINOR.PATCH triggers exact-tag
verification, a tag-derived npm version, tests, package build and npm publication
with provenance. A separate workflow generates the changelog and uploads the
shared release banner. A push or tag alone does not publish a package.
The npm Trusted Publisher authorizes GitHub owner RentnerKev, repository
RentnerMenu and workflow filename npm-publish.yml. Releases use short-lived
OIDC credentials without a stored npm token. See
automation setup.
MIT © RentnerKev
See Contributing, the Code of Conduct, Support, and the Security Policy.
