Jone

Context Menu

A high-quality, unstyled React context menu component that appears at the pointer on right click or long press.

A menu that appears at the pointer on right click or long press.

Right click here

Anatomy

Import the components and place them together:

Anatomy
import { ContextMenu } from '@base-ui/react/context-menu';

<ContextMenu.Root>
  <ContextMenu.Trigger />
  <ContextMenu.Portal>
    <ContextMenu.Backdrop />
    <ContextMenu.Positioner>
      <ContextMenu.Popup>
        <ContextMenu.Arrow />
        <ContextMenu.Item />
        <ContextMenu.LinkItem />
        <ContextMenu.Separator />
        <ContextMenu.Group>
          <ContextMenu.GroupLabel />
        </ContextMenu.Group>
        <ContextMenu.RadioGroup>
          <ContextMenu.RadioItem />
        </ContextMenu.RadioGroup>
        <ContextMenu.CheckboxItem />
        <ContextMenu.SubmenuRoot>
          <ContextMenu.SubmenuTrigger />
        </ContextMenu.SubmenuRoot>
      </ContextMenu.Popup>
    </ContextMenu.Positioner>
  </ContextMenu.Portal>
</ContextMenu.Root>;

Examples

Menu displays additional demos, many of which apply to the context menu as well.

Nested menu

To create a submenu, create a <ContextMenu.SubmenuRoot> inside the parent context menu. Use the <ContextMenu.SubmenuTrigger> part for the menu item that opens the nested menu.

Right click here

API reference

API Documentation for ContextMenu not found.

Portal

NameTypeDefaultDescription
keepMountedOptionalboolean | undefinedfalseWhether to keep the portal mounted in the DOM while the popup is hidden.

Popup

NameTypeDefaultDescription
childrenOptionalReact.ReactNode——
idOptionalstring | undefined—@ignore

Item

NameTypeDefaultDescription
onClickOptionalBaseUIComponentProps<'div', MenuItemState>['onClick'] | undefined—The click handler for the menu item.
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.
labelOptionalstring | undefined—Overrides the text label to use when the item is matched during keyboard text navigation.
idOptionalstring | undefined—@ignore
closeOnClickOptionalboolean | undefinedtrueWhether to close the menu when the item is clicked.

LinkItem

NameTypeDefaultDescription
labelOptionalstring | undefined—Overrides the text label to use when the item is matched during keyboard text navigation.
idOptionalstring | undefined—@ignore
closeOnClickOptionalboolean | undefinedfalseWhether to close the menu when the item is clicked.

SubmenuRoot

NameTypeDefaultDescription
closeParentOnEscOptionalboolean | undefinedfalseWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.

SubmenuTrigger

NameTypeDefaultDescription
onClickOptionalBaseUIComponentProps<'div', MenuSubmenuTriggerState>['onClick'] | undefined——
labelOptionalstring | undefined—Overrides the text label to use when the item is matched during keyboard text navigation.
idOptionalstring | undefined—@ignore
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.
delayOptionalnumber | undefined100How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
closeDelayOptionalnumber | undefined0How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop.
openOnHoverOptionalboolean | undefined—Whether the menu should also open when the trigger is hovered.

Group

NameTypeDefaultDescription
childrenOptionalReact.ReactNode—The content of the component.

RadioGroup

NameTypeDefaultDescription
childrenOptionalReact.ReactNode—The content of the component.
valueOptionalany—The controlled value of the radio item that should be currently selected. To render an uncontrolled radio group, use the `defaultValue` prop instead.
defaultValueOptionalany—The uncontrolled value of the radio item that should be initially selected. To render a controlled radio group, use the `value` prop instead.
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.

RadioItem

NameTypeDefaultDescription
valueRequiredany—Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected.
onClickOptionalBaseUIComponentProps<'div', MenuRadioItemState>['onClick'] | undefined—The click handler for the menu item.
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.
labelOptionalstring | undefined—Overrides the text label to use when the item is matched during keyboard text navigation.
idOptionalstring | undefined—@ignore
closeOnClickOptionalboolean | undefinedfalseWhether to close the menu when the item is clicked.

RadioItemIndicator

NameTypeDefaultDescription
keepMountedOptionalboolean | undefinedfalseWhether to keep the HTML element in the DOM when the radio item is inactive.

CheckboxItem

NameTypeDefaultDescription
checkedOptionalboolean | undefined—Whether the checkbox item is currently ticked. To render an uncontrolled checkbox item, use the `defaultChecked` prop instead.
defaultCheckedOptionalboolean | undefinedfalseWhether the checkbox item is initially ticked. To render a controlled checkbox item, use the `checked` prop instead.
onClickOptionalBaseUIComponentProps<'div', MenuCheckboxItemState>['onClick'] | undefined—The click handler for the menu item.
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.
labelOptionalstring | undefined—Overrides the text label to use when the item is matched during keyboard text navigation.
idOptionalstring | undefined—@ignore
closeOnClickOptionalboolean | undefinedfalseWhether to close the menu when the item is clicked.

CheckboxItemIndicator

NameTypeDefaultDescription
keepMountedOptionalboolean | undefinedfalseWhether to keep the HTML element in the DOM when the checkbox item is not checked.

On this page