components/menu/index.en-US.md
Navigation is an important part of any website, as a good navigation setup allows users to move around the site quickly and efficiently. Ant Design offers two navigation options: top and side. Top navigation provides all the categories and functions of the website. Side navigation provides the multi-level structure of the website.
More layouts with navigation: Layout.
ul element, so it only supports li and script-supporting elements as children nodes. Your customized node should be wrapped by Menu.Item.Menu.* or encapsulated HOCs.<code src="./demo/horizontal.tsx">Top Navigation</code> <code src="./demo/horizontal-dark.tsx" debug>Top Navigation (dark)</code> <code src="./demo/inline.tsx">Inline menu</code> <code src="./demo/inline-collapsed.tsx">Collapsed inline menu</code> <code src="./demo/tooltip.tsx">Menu tooltip</code> <code src="./demo/sider-current.tsx">Open current submenu only</code> <code src="./demo/vertical.tsx">Vertical menu</code> <code src="./demo/theme.tsx">Menu Themes</code> <code src="./demo/submenu-theme.tsx">Sub-menu theme</code> <code src="./demo/switch-mode.tsx">Switch the menu type</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/style-debug.tsx" debug>Style debug</code> <code src="./demo/menu-v4.tsx" debug>Menu v4</code> <code src="./demo/component-token.tsx" debug>Component Token</code> <code src="./demo/extra-style.tsx" debug>Extra Style debug</code> <code src="./demo/custom-popup-render.tsx">Custom Submenu Render</code> <code src="./demo/collapsed-icon-debug.tsx" debug>Collapsed menu icon alignment</code>
Common props ref:Common props
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | |
| defaultOpenKeys | Array with the keys of default opened sub menus | string[] | - | |
| defaultSelectedKeys | Array with the keys of default selected menu items | string[] | - | |
| expandIcon | custom expand icon of submenu | ReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode | - | 4.9.0 |
| forceSubMenuRender | Render submenu into DOM before it becomes visible | boolean | false | |
| inlineCollapsed | Specifies the collapsed status when menu is inline mode | boolean | - | |
| inlineIndent | Indent (in pixels) of inline menu items on each level | number | 24 | |
| items | Menu item content | ItemType[] | - | 4.20.0 |
| mode | Type of menu | vertical | horizontal | inline | vertical | |
| multiple | Allows selection of multiple items | boolean | false | |
| openKeys | Array with the keys of currently opened sub-menus | string[] | - | |
| overflowedIndicator | Customized the ellipsis icon when menu is collapsed horizontally | ReactNode | <EllipsisOutlined /> | |
| selectable | Allows selecting menu items | boolean | true | |
| selectedKeys | Array with the keys of currently selected menu items | string[] | - | |
| style | Style of the root node | CSSProperties | - | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | |
| subMenuCloseDelay | Delay time to hide submenu when mouse leaves (in seconds) | number | 0.1 | |
| subMenuOpenDelay | Delay time to show submenu when mouse enters, (in seconds) | number | 0 | |
| tooltip | Config tooltip props for menu items in inline collapsed mode. Set to false to disable. | false | TooltipProps | - | 6.3.0 |
| theme | Color theme of the menu | light | dark | light | |
| triggerSubMenuAction | Which action can trigger submenu open/close | hover | click | hover | |
| onClick | Called when a menu item is clicked | function({ key, keyPath, domEvent }) | - | |
| onDeselect | Called when a menu item is deselected (multiple mode only) | function({ key, keyPath, selectedKeys, domEvent }) | - | |
| onOpenChange | Called when sub-menus are opened or closed | function(openKeys: string[]) | - | |
| onSelect | Called when a menu item is selected | function({ key, keyPath, selectedKeys, domEvent }) | - | |
| popupRender | Custom popup renderer for submenu | (node: ReactElement, props: { item: SubMenuProps; keys: string[] }) => ReactElement | - |
More options in @rc-component/menu
type ItemType = MenuItemType | SubMenuType | MenuItemGroupType | MenuDividerType;
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| danger | Display the danger style | boolean | false | |
| disabled | Whether menu item is disabled | boolean | false | |
| extra | The extra of the menu item | ReactNode | - | 5.21.0 |
| icon | The icon of the menu item | ReactNode | - | |
| key | Unique ID of the menu item | string | - | |
| label | Menu label | ReactNode | - | |
| title | Set display title for collapsed item | string | - |
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| children | Sub-menus or sub-menu items | ItemType[] | - | |
| disabled | Whether sub-menu is disabled | boolean | false | |
| icon | Icon of sub menu | ReactNode | - | |
| key | Unique ID of the sub-menu | string | - | |
| label | Menu label | ReactNode | - | |
| popupClassName | Sub-menu class name, not working when mode="inline" | string | - | |
| popupOffset | Sub-menu offset, not working when mode="inline" | [number, number] | - | |
| theme | Color theme of the SubMenu (inherits from Menu by default) | light | dark | - | |
| onTitleClick | Callback executed when the sub-menu title is clicked | function({ key, domEvent }) | - | |
| popupRender | Custom popup renderer for current sub-menu | (node: ReactElement, props: { item: SubMenuProps; keys: string[] }) => ReactElement | - |
Define type as group to make as group:
const groupItem = {
type: 'group', // Must have
label: 'My Group',
children: [],
};
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| children | Sub-menu items | MenuItemType[] | - | |
| label | The title of the group | ReactNode | - |
Divider line in between menu items, only used in vertical popup Menu or Dropdown Menu. Need define the type as divider:
const dividerItem = {
type: 'divider', // Must have
};
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| dashed | Whether line is dashed | boolean | false |
Menu collects structure info with twice-render to support HOC usage. Merging into one render may cause the logic to become much more complex. Contributions to help improve the collection logic are welcomed.
Menu will render fully item in flex layout and then collapse it. You need tell flex not consider Menu width to enable responsive (online demo):
<div style={{ flex }}>
<div style={{ ... }}>Some Content</div>
<Menu style={{ minWidth: 0, flex: "auto" }} />
</div>
<code src="./demo/_semantic.tsx" simplify="true"></code>
<ComponentTokenTable component="Menu"></ComponentTokenTable>