rc-menu: Core React Menu Component

9.16.1 · renamed · verified Sun Apr 19

rc-menu is a foundational, unstyled React UI component designed for building highly customizable and accessible hierarchical menus. It provides the core logic and composable primitives like `Menu`, `SubMenu`, and `MenuItem`, offering developers extensive control over styling and behavior. While widely adopted, the `rc-menu` package, currently at version `9.16.1`, is in a maintenance-only state with its last publish over a year ago. Active development and new features have migrated to the `@rc-component/menu` package (latest v1.2.0), which is the recommended choice for new projects and for existing users looking for ongoing support and enhancements. This component is often used as a base for more opinionated UI libraries, such as Ant Design's menu, due to its low-level control.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates a basic `rc-menu` setup with a root menu, a submenu, and individual menu items, including a disabled item, rendered into a DOM element. It also includes the necessary CSS import for basic functionality.

import React from 'react';
import ReactDOM from 'react-dom/client';
import Menu, { SubMenu, MenuItem } from 'rc-menu';
import 'rc-menu/assets/index.css'; // Don't forget to import basic styles if needed

const App = () => (
  <div>
    <h2>Basic rc-menu Example</h2>
    <Menu style={{ width: 200, border: '1px solid #ddd' }}>
      <MenuItem key="1">Option 1</MenuItem>
      <SubMenu key="sub1" title="Submenu">
        <MenuItem key="2-1">Sub-option 2-1</MenuItem>
        <MenuItem key="2-2">Sub-option 2-2</MenuItem>
      </SubMenu>
      <MenuItem key="3" disabled>Disabled Option 3</MenuItem>
    </Menu>
  </div>
);

const container = document.getElementById('root');
if (container) {
  const root = ReactDOM.createRoot(container);
  root.render(<App />);
} else {
  console.error("Root element not found. Please ensure a div with id 'root' exists in your HTML.");
}

view raw JSON →