Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rc-menu

react-component5.2mMIT9.16.0TypeScript support: included

menu ui component for react

react, react-component, menu, ui, react-menu

readme

rc-menu


React Menu Component. port from https://github.com/kissyteam/menu

NPM version npm download build status Codecov bundle size dumi

Install

rc-menu

Usage

import Menu, { SubMenu, MenuItem } from 'rc-menu';

ReactDOM.render(
  <Menu>
    <MenuItem>1</MenuItem>
    <SubMenu title="2">
      <MenuItem>2-1</MenuItem>
    </SubMenu>
  </Menu>,
  container,
);

Compatibility

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Electron
Electron
IE11, Edge last 2 versions last 2 versions last 2 versions last 2 versions

API

name type default description
ref React.HTMLLIElement get dom node
className String additional css class of root dom node
mode String vertical one of ["horizontal","inline","vertical-left","vertical-right"]
activeKey String initial and current active menu item's key.
defaultActiveFirst Boolean false whether active first menu item when show if activeKey is not set or invalid
multiple Boolean false whether allow multiple select
selectable Boolean true allow selecting menu items
selectedKeys String[] [] selected keys of items
defaultSelectedKeys String[] [] initial selected keys of items
openKeys String[] [] open keys of SubMenuItem
defaultOpenKeys String[] [] initial open keys of SubMenuItem
onSelect function({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]}) called when select a menu item
onClick function({key:String, item:ReactComponent, domEvent:Event, keyPath: String[]}) called when click a menu item
onOpenChange (openKeys:String[]) => void called when open/close sub menu
onDeselect function({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]}) called when deselect a menu item. only called when allow multiple
triggerSubMenuAction Enum { hover, click } hover which action can trigger submenu open/close
openAnimation {enter:function,leave:function}|String animate when sub menu open or close. see rc-motion for object type.
openTransition String css transitionName when sub menu open or close
subMenuOpenDelay Number 0 delay time to show popup sub menu. unit: s
subMenuCloseDelay Number 0.1 delay time to hide popup sub menu. unit: s
forceSubMenuRender Boolean false whether to render submenu even if it is not visible
getPopupContainer Function(menuDOMNode): HTMLElement () => document.body Where to render the DOM node of popup menu when the mode is horizontal or vertical
builtinPlacements Object of alignConfigs for dom-align see placements.ts Describes how the popup menus should be positioned
itemIcon ReactNode | (props: MenuItemProps) => ReactNode Specify the menu item icon.
expandIcon ReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode Specify the menu item icon.
direction String Layout direction of menu component, it supports RTL direction too.
inlineIndent Number 24 Padding level multiplier. Right or left padding depends on param "direction".
name type default description
className String additional css class of root dom node
disabled Boolean false no effect for click or keydown for this item
extra React.ReactNode Specify menu item extra node.
key Object corresponding to activeKey
onMouseEnter Function({eventKey, domEvent})
onMouseLeave Function({eventKey, domEvent})
itemIcon ReactNode | (props: MenuItemProps) => ReactNode Specify the menu item icon.
name type default description
ref React.HTMLLIElement get dom node
popupClassName String additional css class of root dom node
popupStyle CSSProperties additional css style of root dom node
title String/ReactElement sub menu's content
overflowedIndicator String/ReactElement ··· overflow indicator when menu overlows in horizontal mode
key Object corresponding to activeKey
disabled Boolean false no effect for click or keydown for this item
onMouseEnter Function({eventKey, domEvent})
onMouseLeave Function({eventKey, domEvent})
onTitleMouseEnter Function({eventKey, domEvent})
onTitleMouseLeave Function({eventKey, domEvent})
onTitleClick Function({eventKey, domEvent})
popupOffset Array The offset of the popup submenu, in an x, y coordinate array. e.g.: `[0,15]`
expandIcon ReactNode | (props: SubMenuProps) => ReactNode Specify the menu item icon.
itemIcon ReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode Specify the menu item icon.

none

name type default description
ref React.HTMLLIElement get dom node
title String|React.Element title of item group
children React.Element[] MenuItems belonged to this group

Development

npm install
npm start

Example

http://localhost:8001/examples/index.md

online example: http://react-component.github.io/menu/examples/

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rc-menu is released under the MIT license.

changelog

Changelog

8.1.0 / 2020-05-08

  • Upgrade rc-animate to 3.x

7.5.0 / 2019-10-14

  • Use CSSMotion instead of Animate

7.4.0 / 2019-08-31

  • Support overflow collapse menu

7.3.0 / 2018-08-23

  • Add expandIcon and itemIcon. #182

7.0.2 / 2018-05-03

  • Better aria-* attributes support.
  • Improve Menu performance by avoiding unnecessary updates.
  • Minor key shortcut bug fixes.
  • Support passing props through to MenuItem list item

6.0.0 / 2017-10-30

  • Replace openSubMenuOnMouseEnter/closeSubMenuOnMouseLeave with triggerSubMenuAction
  • Add subMenuCloseDelay and subMenuOpenDelay
  • Refactor with rc-trigger

5.1.0 / 2016-09-12

  • Add dom for submenu arrow

5.0.0 / 2016-08-19

  • remove onOpen/onClose, support onOpenChange(openKeys: string[])

4.13.0 / 2016-07-22

  • support submenu-selected

4.12 / 2016-05-05

  • make submenu active only title is hovered when inline

4.11.0 / 2016-04-27

  • add onMouseEnter/onTitleMouseLeave/onTitleClick/...

4.10.0 / 2016-01-20

  • use es6 export

4.9.0 / 2015-12-25

  • add keyPath to onOpen/onClose argument info

4.6.0 / 2015-09-16

  • add keyPath to onClick argument info

4.5.0 / 2015-09-14

  • does not hide submenu when click(use onClick to set openKeys to [] if you want)

4.4.0 / 2015-08-13

  • add openAnimation/openTransitionName prop

4.3.0 / 2015-08-13

  • make selectedKeys openedKeys controllable
  • add closeSubMenuOnMouseLeave/onOpen/onClose props

4.1.0 / 2015-08-11

  • remove openOnHover for SubMenu
  • add openSubMenuOnMouseEnter prop for Menu

4.0.0 / 2015-08-10

  • add props: mode (horizontal, vertical, inline) for Menu
  • add defaultSelectedKeys, make selectedKeys controllable
  • change param of onSelect onDeselect

3.5.0 / 2015-08-06

add props: vertical/horizontal for Menu, align for SubMenu

3.4.0 / 2015-06-17

improved #9 allow not set key for menuitem

new #10 support MenuItemGroup

3.3.0 / 2015-06-08

new add Menu.Divider Component

3.1.0 / 2015-03-26

improved #5 support selected and disabled for menuitem simultaneously

3.0.0 / 2015-03-17

support react 0.13 and es6

2.2.0 / 2015-01-29

new #3 support scrollIntoView if menu is scrollable

new #2 support multiple prop and onDeselect callback