Menu

A versatile menu for navigation.
Importimport{ Menu }from"antd";

When To Use

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.

Notes for developers

  • Menu is rendered as a ul element, so it only supports li and script-supporting elements as children nodes。Your customized node should be wrapped by Menu.Item.
  • Menu needs to collect its node structure, so its children should be Menu.* or encapsulated HOCs.

Examples

API

Common props ref:Common props

ParamDescriptionTypeDefault valueVersion
defaultOpenKeysArray with the keys of default opened sub menusstring[]-
defaultSelectedKeysArray with the keys of default selected menu itemsstring[]-
expandIconcustom expand icon of submenuReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode-4.9.0
forceSubMenuRenderRender submenu into DOM before it becomes visiblebooleanfalse
inlineCollapsedSpecifies the collapsed status when menu is inline modeboolean-
inlineIndentIndent (in pixels) of inline menu items on each levelnumber24
itemsMenu item contentItemType[]-4.20.0
modeType of menuvertical | horizontal | inlinevertical
multipleAllows selection of multiple itemsbooleanfalse
openKeysArray with the keys of currently opened sub-menusstring[]-
overflowedIndicatorCustomized the ellipsis icon when menu is collapsed horizontallyReactNode<EllipsisOutlined />
selectableAllows selecting menu itemsbooleantrue
selectedKeysArray with the keys of currently selected menu itemsstring[]-
styleStyle of the root nodeCSSProperties-
subMenuCloseDelayDelay time to hide submenu when mouse leaves (in seconds)number0.1
subMenuOpenDelayDelay time to show submenu when mouse enters, (in seconds)number0
themeColor theme of the menulight | darklight
triggerSubMenuActionWhich action can trigger submenu open/closehover | clickhover
onClickCalled when a menu item is clickedfunction({ item, key, keyPath, domEvent })-
onDeselectCalled when a menu item is deselected (multiple mode only)function({ item, key, keyPath, selectedKeys, domEvent })-
onOpenChangeCalled when sub-menus are opened or closedfunction(openKeys: string[])-
onSelectCalled when a menu item is selectedfunction({ item, key, keyPath, selectedKeys, domEvent })-

More options in rc-menu

ItemType

type ItemType = MenuItemType | SubMenuType | MenuItemGroupType | MenuDividerType;

ParamDescriptionTypeDefault valueVersion
dangerDisplay the danger stylebooleanfalse
disabledWhether menu item is disabledbooleanfalse
extraThe extra of the menu itemReactNode-5.21.0
iconThe icon of the menu itemReactNode-
keyUnique ID of the menu itemstring-
labelMenu labelReactNode-
titleSet display title for collapsed itemstring-
PropertyDescriptionTypeDefault valueVersion
childrenSub-menus or sub-menu itemsItemType[]-
disabledWhether sub-menu is disabledbooleanfalse
iconIcon of sub menuReactNode-
keyUnique ID of the sub-menustring-
labelMenu labelReactNode-
popupClassNameSub-menu class name, not working when mode="inline"string-
popupOffsetSub-menu offset, not working when mode="inline"[number, number]-
themeColor theme of the SubMenu (inherits from Menu by default)light | dark-
onTitleClickCallback executed when the sub-menu title is clickedfunction({ key, domEvent })-

Define type as group to make as group:

const groupItem = {
type: 'group', // Must have
label: 'My Group',
children: [],
};
ParamDescriptionTypeDefault valueVersion
childrenSub-menu itemsMenuItemType[]-
labelThe title of the groupReactNode-

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
};
ParamDescriptionTypeDefault valueVersion
dashedWhether line is dashedbooleanfalse

FAQ

Why will Menu's children be rendered twice?

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.

Why Menu do not responsive collapse in Flex layout?

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>

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
activeBarBorderWidthBorder width of menu item active barstring | number1
activeBarHeightHeight of menu item active barnumber2
activeBarWidthWidth of menu item active barstring | number0
collapsedIconSizeSize of icon when collapsednumber16
collapsedWidthWidth when collapsedstring | number80
dangerItemActiveBgColor of active danger menu item textstring#fff2f0
dangerItemColorColor of danger menu item textstring#ff4d4f
dangerItemHoverColorHover color of danger menu item textstring#ff4d4f
dangerItemSelectedBgColor of selected danger menu item textstring#fff2f0
dangerItemSelectedColorColor of selected danger menu item textstring#ff4d4f
darkDangerItemActiveBgBackground of active danger menu item in dark modestring#ff4d4f
darkDangerItemColorColor of danger menu item text in dark modestring#ff4d4f
darkDangerItemHoverColorBackground of hovered danger menu item in dark modestring#ff7875
darkDangerItemSelectedBgBackground of active danger menu item in dark modestring#ff4d4f
darkDangerItemSelectedColorColor of selected danger menu item in dark modestring#fff
darkGroupTitleColorColor of group title text in dark modestringrgba(255,255,255,0.65)
darkItemBgBackground of menu item in dark modestring#001529
darkItemColorColor of menu item text in dark modestringrgba(255,255,255,0.65)
darkItemDisabledColorColor of disabled menu item in dark modestringrgba(255,255,255,0.25)
darkItemHoverBgBackground of hovered menu item in dark modestringtransparent
darkItemHoverColorColor of hovered menu item in dark modestring#fff
darkItemSelectedBgBackground of active menu item in dark modestring#1677ff
darkItemSelectedColorColor of selected menu item in dark modestring#fff
darkPopupBgThe background color of the overlay menu in dark mode.string#001529
darkSubMenuItemBgBackground of submenu item in dark modestring#000c17
dropdownWidthWidth of popup menustring | number160
groupTitleColorColor of group title textstringrgba(0,0,0,0.45)
groupTitleFontSizefont-size of group titlenumber14
groupTitleLineHeightline-height of group titlestring | number1.5714285714285714
horizontalItemBorderRadiusBorder radius of horizontal menu itemnumber0
horizontalItemHoverBgBackground color of horizontal menu item when hoverstringtransparent
horizontalItemHoverColorHover color of horizontal menu item textstring#1677ff
horizontalItemSelectedBgBackground color of horizontal menu item when selectedstringtransparent
horizontalItemSelectedColorColor of selected horizontal menu item textstring#1677ff
horizontalLineHeightLineHeight of horizontal menu itemundefined | LineHeight<string | number>46px
iconMarginInlineEndSpacing between icon and textundefined | MarginInlineEnd<string | number>10
iconSizeSize of iconnumber14
itemActiveBgBackground color of menu item when activestring#e6f4ff
itemBgstring#ffffff
itemBorderRadiusRadius of menu itemnumber8
itemColorColor of menu item textstringrgba(0,0,0,0.88)
itemDisabledColorColor of disabled menu item textstringrgba(0,0,0,0.25)
itemHeightHeight of menu itemstring | number40
itemHoverBgBackground color of menu item when hoverstringrgba(0,0,0,0.06)
itemHoverColorHover color of menu item textstringrgba(0,0,0,0.88)
itemMarginBlockmargin-block of menu itemundefined | MarginBlock<string | number>4
itemMarginInlineHorizontal margin of menu itemnumber4
itemPaddingInlinepadding-inline of menu itemundefined | PaddingInline<string | number>16
itemSelectedBgBackground color of menu item when selectedstring#e6f4ff
itemSelectedColorColor of selected menu item textstring#1677ff
popupBgBackground color of popupstring#ffffff
subMenuItemBgBackground color of sub-menu itemstringrgba(0,0,0,0.02)
subMenuItemBorderRadiusRadius of sub-menu itemnumber4
subMenuItemSelectedColorColor of submenu title when submenu has selected itemstring#1677ff
zIndexPopupz-index of popup menunumber1050

Global TokenHow to use?