Socket
Socket
Sign inDemoInstall

rc-menu

Package Overview
Dependencies
16
Maintainers
10
Versions
275
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-menu

menu ui component for react


Version published
Weekly downloads
1.4M
increased by5.8%
Maintainers
10
Install size
1.31 MB
Created
Weekly downloads
 

Package description

What is rc-menu?

The rc-menu package is a React component for building menus. It provides a flexible and accessible way to create dropdown, context, and other types of menus in your web application. It supports features like keyboard navigation, animation, and customization through themes.

What are rc-menu's main functionalities?

Basic Menu

This code sample demonstrates how to create a basic menu with three options. When an option is selected, it logs the key of the selected item.

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

<Menu onSelect={({ key }) => console.log(key)}>
  <MenuItem key="1">Option 1</MenuItem>
  <MenuItem key="2">Option 2</MenuItem>
  <MenuItem key="3">Option 3</MenuItem>
</Menu>

Sub Menu

This example shows how to create a menu with a sub-menu. The sub-menu contains two options, demonstrating how to nest menus within each other.

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

<Menu>
  <SubMenu title="Sub Menu">
    <MenuItem key="sub1">Option 1</MenuItem>
    <MenuItem key="sub2">Option 2</MenuItem>
  </SubMenu>
</Menu>

Vertical Menu

This snippet illustrates how to create a vertical menu by setting the mode prop to 'vertical'. It's useful for sidebar navigation.

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

<Menu mode="vertical">
  <MenuItem key="1">Option 1</MenuItem>
  <MenuItem key="2">Option 2</MenuItem>
  <MenuItem key="3">Option 3</MenuItem>
</Menu>

Other packages similar to rc-menu

Readme

Source

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, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

API

Menu props

nametypedefaultdescription
classNameStringadditional css class of root dom node
modeStringverticalone of ["horizontal","inline","vertical-left","vertical-right"]
activeKeyStringinitial and current active menu item's key.
defaultActiveFirstBooleanfalsewhether active first menu item when show if activeKey is not set or invalid
multipleBooleanfalsewhether allow multiple select
selectableBooleantrueallow selecting menu items
selectedKeysString[][]selected keys of items
defaultSelectedKeysString[][]initial selected keys of items
openKeysString[][]open keys of SubMenuItem
defaultOpenKeysString[][]initial open keys of SubMenuItem
onSelectfunction({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]})called when select a menu item
onClickfunction({key:String, item:ReactComponent, domEvent:Event, keyPath: String[]})called when click a menu item
onOpenChange(openKeys:String[]) => voidcalled when open/close sub menu
onDeselectfunction({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]})called when deselect a menu item. only called when allow multiple
triggerSubMenuActionEnum { hover, click }hoverwhich action can trigger submenu open/close
openAnimation{enter:function,leave:function}|Stringanimate when sub menu open or close. see rc-motion for object type.
openTransitionStringcss transitionName when sub menu open or close
subMenuOpenDelayNumber0delay time to show popup sub menu. unit: s
subMenuCloseDelayNumber0.1delay time to hide popup sub menu. unit: s
forceSubMenuRenderBooleanfalsewhether to render submenu even if it is not visible
getPopupContainerFunction(menuDOMNode): HTMLElement() => document.bodyWhere to render the DOM node of popup menu when the mode is horizontal or vertical
builtinPlacementsObject of alignConfigs for dom-alignsee placements.tsDescribes how the popup menus should be positioned
itemIconReactNode | (props: MenuItemProps) => ReactNodeSpecify the menu item icon.
expandIconReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNodeSpecify the menu item icon.
directionStringLayout direction of menu component, it supports RTL direction too.
inlineIndentNumber24Padding level multiplier. Right or left padding depends on param "direction".

Menu.Item props

nametypedefaultdescription
classNameStringadditional css class of root dom node
disabledBooleanfalseno effect for click or keydown for this item
keyObjectcorresponding to activeKey
onMouseEnterFunction({eventKey, domEvent})
onMouseLeaveFunction({eventKey, domEvent})
itemIconReactNode | (props: MenuItemProps) => ReactNodeSpecify the menu item icon.

Menu.SubMenu props

nametypedefaultdescription
popupClassNameStringadditional css class of root dom node
popupStyleCSSPropertiesadditional css style of root dom node
titleString/ReactElementsub menu's content
overflowedIndicatorString/ReactElement···overflow indicator when menu overlows in horizontal mode
keyObjectcorresponding to activeKey
disabledBooleanfalseno effect for click or keydown for this item
onMouseEnterFunction({eventKey, domEvent})
onMouseLeaveFunction({eventKey, domEvent})
onTitleMouseEnterFunction({eventKey, domEvent})
onTitleMouseLeaveFunction({eventKey, domEvent})
onTitleClickFunction({eventKey, domEvent})
popupOffsetArrayThe offset of the popup submenu, in an x, y coordinate array. e.g.: `[0,15]`
expandIconReactNode | (props: SubMenuProps) => ReactNodeSpecify the menu item icon.
itemIconReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNodeSpecify the menu item icon.

Menu.Divider props

none

Menu.ItemGroup props

nametypedefaultdescription
titleString|React.Elementtitle of item group
childrenReact.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.

Keywords

FAQs

Last updated on 08 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc