# @rc-component/menu

> menu ui component for react

Latest version **1.6.0** (published 2026-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rc-component/menu
pnpm add @rc-component/menu
yarn add @rc-component/menu
bun add @rc-component/menu
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2026-09-01 |
| First published | 2025-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 222.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 701 |
| Maintainers | zombiej, afc163, madccc, peachscript, chenshuai2144 |
| Keywords | react, react-component, menu, ui, react-menu |

## Links

- npm: https://www.npmjs.com/package/@rc-component/menu
- Repository: https://github.com/react-component/menu
- Homepage: https://react-component.github.io/menu
- Issues: https://github.com/react-component/menu/issues
- npm.io page: https://npm.io/package/@rc-component/menu

## Dependencies (5)

- [clsx](https://npm.io/package/clsx.md) ^2.1.1
- [@rc-component/util](https://npm.io/package/@rc-component/util.md) ^1.11.1
- [@rc-component/motion](https://npm.io/package/@rc-component/motion.md) ^1.1.4
- [@rc-component/trigger](https://npm.io/package/@rc-component/trigger.md) ^3.0.0
- [@rc-component/overflow](https://npm.io/package/@rc-component/overflow.md) ^1.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2026-09-01
- 1.5.0 — 2026-08-19
- 1.4.1 — 2026-06-03
- 1.4.0 — 2026-06-01
- 1.3.1 — 2026-05-28
- 1.3.0 — 2026-05-06
- 1.2.0 — 2025-12-04
- 1.1.5 — 2025-11-26
- 1.1.4 — 2025-09-10
- 1.1.3 — 2025-04-22
- 1.1.2 — 2025-04-09
- 1.1.1 — 2025-04-09
- 1.1.0 — 2025-04-03
- 1.0.1 — 2025-02-26
- 1.0.0 — 2025-02-25

## README

<div align="center">
  <h1>@rc-component/menu</h1>
  <p><sub><a href="https://ant.design"><img alt="Ant Design" height="14" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" style="vertical-align: -0.125em;" /></a> Part of the Ant Design ecosystem.</sub></p>
  <p>🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.</p>

  <p>
    <a href="https://npmjs.org/package/@rc-component/menu"><img alt="NPM version" src="https://img.shields.io/npm/v/@rc-component/menu.svg?style=flat-square"></a>
    <a href="https://npmjs.org/package/@rc-component/menu"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square"></a>
    <a href="https://github.com/react-component/menu/actions/workflows/react-component-ci.yml"><img alt="build status" src="https://github.com/react-component/menu/actions/workflows/react-component-ci.yml/badge.svg"></a>
    <a href="https://app.codecov.io/gh/react-component/menu"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/react-component/menu/master.svg?style=flat-square"></a>
    <a href="https://bundlephobia.com/package/@rc-component/menu"><img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@rc-component/menu?style=flat-square"></a>
    <a href="https://github.com/umijs/dumi"><img alt="dumi" src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square"></a>
  </p>
</div>

<p align="center">English | <a href="./README.zh-CN.md">简体中文</a></p>

## Highlights

- Horizontal, vertical, and inline menu modes.
- Controlled and uncontrolled selection, open keys, and active key state.
- `items` configuration API with legacy children support.
- Sub menus, item groups, dividers, icons, overflow, popup rendering, and keyboard focus helpers.
- TypeScript definitions and semantic `classNames` / `styles` slots.
- Used by Ant Design as the shared menu foundation.

## Install

```bash
npm install @rc-component/menu
```

## Usage

```tsx | pure
import Menu, { type MenuProps } from '@rc-component/menu';

const items: MenuProps['items'] = [
  { key: 'home', label: 'Home' },
  {
    key: 'docs',
    label: 'Docs',
    children: [
      { key: 'quick-start', label: 'Quick start' },
      { key: 'api', label: 'API' },
    ],
  },
];

export default () => (
  <Menu mode="inline" items={items} defaultSelectedKeys={['home']} defaultOpenKeys={['docs']} />
);
```

```tsx | pure
import Menu, { MenuItem, SubMenu } from '@rc-component/menu';

export default () => (
  <Menu>
    <MenuItem key="1">Item 1</MenuItem>
    <SubMenu key="2" title="More">
      <MenuItem key="2-1">Item 2-1</MenuItem>
    </SubMenu>
  </Menu>
);
```

## Examples

Run the local dumi site:

```bash
npm install
npm start
```

Then open `http://localhost:8000`.

## API

### Menu

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| activeKey | `string` | - | Controlled active item key. |
| builtinPlacements | `Record<string, any>` | - | Popup alignment placements for sub menus. |
| className | `string` | - | Class name for the root menu. |
| classNames | `Partial<Record<'list' \| 'listTitle', string>>` | - | Semantic class names for menu slots. |
| defaultActiveFirst | `boolean` | `false` | Focus the first enabled item when active key is absent. |
| defaultOpenKeys | `string[]` | `[]` | Initial open sub menu keys. |
| defaultSelectedKeys | `string[]` | `[]` | Initial selected item keys. |
| defaultMotions | `Partial<Record<MenuMode \| 'other', CSSMotionProps>>` | - | Motion config by menu mode. |
| direction | `'ltr' \| 'rtl'` | - | Layout direction. |
| disabled | `boolean` | `false` | Disable all menu interactions. |
| disabledOverflow | `boolean` | `false` | Disable overflow measurement. |
| expandIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom sub menu expand icon. |
| forceSubMenuRender | `boolean` | `false` | Render popup sub menus before they are opened. |
| getPopupContainer | `(node: HTMLElement) => HTMLElement` | - | Container for popup sub menus. |
| inlineCollapsed | `boolean` | - | Collapse inline menu layout. |
| inlineIndent | `number` | `24` | Indent width for inline mode. |
| itemIcon | `ReactNode \| (props: RenderIconInfo) => ReactNode` | - | Custom item icon. |
| items | `ItemType[]` | - | Menu item configuration. |
| mode | `'horizontal' \| 'vertical' \| 'inline'` | `vertical` | Menu display mode. |
| motion | `CSSMotionProps` | - | Motion config for menu transitions. |
| multiple | `boolean` | `false` | Allow multiple selected items. |
| openKeys | `string[]` | - | Controlled open sub menu keys. |
| overflowedIndicator | `ReactNode` | `"..."` | Indicator rendered for overflowed items. |
| popupRender | `(node, info) => ReactNode` | - | Customize popup menu rendering. |
| prefixCls | `string` | `rc-menu` | Class name prefix. |
| rootClassName | `string` | - | Class name for the root wrapper. |
| selectable | `boolean` | `true` | Allow item selection. |
| selectedKeys | `string[]` | - | Controlled selected item keys. |
| styles | `Partial<Record<'list' \| 'listTitle', CSSProperties>>` | - | Semantic styles for menu slots. |
| subMenuCloseDelay | `number` | `0.1` | Delay in seconds before closing popup sub menus. |
| subMenuOpenDelay | `number` | `0.1` | Delay in seconds before opening popup sub menus. |
| triggerSubMenuAction | `'click' \| 'hover'` | `hover` | Interaction that opens sub menus. |
| onClick | `(info: MenuInfo) => void` | - | Triggered when an item is clicked. |
| onDeselect | `(info: SelectInfo) => void` | - | Triggered when an item is deselected. |
| onOpenChange | `(openKeys: string[]) => void` | - | Triggered when open keys change. |
| onSelect | `(info: SelectInfo) => void` | - | Triggered when an item is selected. |

### ItemType

```ts
type ItemType =
  | {
      type?: 'item';
      // Item keys accept React.Key and are normalized to strings in event info.
      key: React.Key;
      label?: React.ReactNode;
      disabled?: boolean;
      itemIcon?: RenderIconType;
      extra?: React.ReactNode;
    }
  | {
      type?: 'submenu';
      // Sub menu keys are strings to match openKeys/defaultOpenKeys.
      key: string;
      label?: React.ReactNode;
      children: ItemType[];
      disabled?: boolean;
    }
  | {
      type: 'group';
      label?: React.ReactNode;
      children?: ItemType[];
    }
  | {
      type: 'divider';
    };
```

### Ref

| Method | Type | Description |
| --- | --- | --- |
| `focus` | `(options?: FocusOptions) => void` | Focus the active item or first enabled item. |
| `findItem` | `({ key: string }) => HTMLElement \| null` | Find the DOM element for an item key. |
| `list` | `HTMLUListElement` | Root menu list element. |

## Development

```bash
npm install
npm start
npm test
npm run tsc
npm run compile
npm run build
```

The dumi site runs at `http://localhost:8000` by default.

## Release

```bash
npm run prepublishOnly
```

The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build.

## License

@rc-component/menu is released under the [MIT](./LICENSE) license.

---
_Source: https://npm.io/package/@rc-component/menu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
