API

August 15, 2019 · View on GitHub

The module exports the following:

  • ContextMenu
  • ContextMenuTrigger
  • MenuItem
  • SubMenu

<ContextMenu />

Base Contextmenu Component.

PropTypes

PropertyTypeRequired?Description
idStringA unique identifier for a menu.
hideOnLeaveBooleanHides the context menu on mouse leave.
onMouseLeaveFunctionCallback called when the mouse leaves the menu or submenu areas.
onHideFunctionCallback called when the menu is hidden.
onShowFunctionCallback called when the menu is shown.
preventHideOnContextMenuBooleanPrevents hiding of the context menu on contextMenu event.
preventHideOnResizeBooleanPrevents hiding of the context menu on resize event.
preventHideOnScrollBooleanPrevents hiding of the context menu on scroll event.
classNameStringCustom className applied to root element of the context-menu.

<ContextMenuTrigger />

Contextmenu Trigger Component

PropTypes

PropertyTypeRequired?DefaultDescription
idStringThe unique identifier of the menu to be called.
attributesObjectThe attributes will be passed directly passed to the root element of component. Use this to customize it like adding custom classes, adding colspan etc.
collectFunctionA simple function which takes props as input and returns the data to be passed to contextmenu.
disableBooleanfalseProp to ignore right clicks and display the default browser context menu.
holdToDisplayNumber1000This is applicable only for touch screens. The time (in ms) for which, user has to hold down his/her finger before the menu is shown. Note: To disable the long press trigger on left-click just set a negative holdToDisplay value such as -1
renderTagString or React ElementThe element inside which the Component must be wrapped. By default div is used. But this prop can used to customize it.
disableIfShiftIsPressedBooleanfalseIf true and shift is pressed, it will open the native browser context menu and ignore this custom component

A Simple Component for menu items.

PropTypes

PropertyTypeRequired?DefaultDescription
onClickFunctionThe function to be called on click of item. The function will receive three parameters. The first is event object. The second is the merged data passed using props.data and collect from ContextMenuTrigger. The third is the element on which right-click occured.
dataObject{}The extra data (if required) to be passed to onClick event.
disabledBooleanfalseIf true, disables the click event and adds .disabled class.
preventCloseBooleanfalseBy default, the context menu is closed as soon as an item is clicked. Set this prop to control this behavior.
attributesObjectThe attributes will be passed directly passed to the root element of MenuItem. Use this to customize it like adding custom classes (className, disabledClassName, dividerClassName and selectedClassName), etc.
selectedbooleanfalseInternal Prop: will be set from the surrounded context ContextMenu or SubMenu. If set to true the css class react-contextmenu-item--selected will be added to associated element.
onMouseMoveFunctionInternal Prop: will be directly passed to associated element, so the surrounded context ContextMenu or SubMenu can handle the interactions to pass the correct selected state. Also the surrounded context can store the current selected MenuItem.
onMouseLeaveFunctionInternal Prop: will be directly passed to associated element, so the surrounded context ContextMenu or SubMenu can handle the interactions to pass the correct selected state. Also the surrounded context can store the current selected MenuItem.

A component for using submenus within the contextmenu.

PropTypes

PropertyTypeRequired?DefaultDescription
titleStringThe content to be displayed in parent menu.
disabledBooleanfalseIf true, disables the menu from opening and adds .disabled class.
hoverDelayNumber500The time (in ms) after which the menu is to be displayed when hovered upon.
classNameStringCustom className applied to root element of the context-menu.
attributesObjectThe attributes will be passed directly passed to the root element of SubMenu. Use this to customize it like adding custom classes (className, disabledClassName, visibleClassName, selectedClassName and listClassName), etc.
selectedbooleanfalseInternal Prop: will be set from the surrounded context ContextMenu or SubMenu. If set to true the css class react-contextmenu-item--selected will be added to associated element.
onClickFunctionThe function to be called on click of SubMenu. The function will receive three parameters. The first is event object. The second is the merged data passed using props.data and collect from ContextMenuTrigger. The third is the element on which right-click occured.
onMouseMoveFunctionInternal Prop: will be directly passed to associated element, so the surrounded context ContextMenu or SubMenu can handle the interactions to pass the correct selected state. Also the surrounded context can store the current selected SubMenu entry.
onMouseOutFunctionInternal Prop: will be directly passed to associated element, so the surrounded context ContextMenu or SubMenu can handle the interactions to pass the correct selected state. Also the surrounded context can store the current selected SubMenu entry.
preventCloseOnClickBooleanfalsePrevent the context-menu to close when clicking on this SubMenu.
forceOpenbooleanfalseInternal Prop: if the user hits enter or the right arrow key on a selected SubMenu entry, the surrounded context will pass true to this flag. The SubMenu stays open until this flag is false.
forceCloseFunctionInternal Prop: if the user hits the escape key during an open SubMenu, this function will be called to indicate the surrounding context to reset the forceOpen flag.
parentKeyNavigationHandlerFunctionInternal Prop: the keydown handler from the surrounding context will be passed to every open SubMenu. Then the Submenu will unregister the referenced handler and use it's own for key control. When the SubMenu hides again the original handler will be restored.