Context Menu

Displays a menu of actions triggered by a right-click (or long-press on touch devices).

Installation

pnpm add @notion-kit/ui

Anatomy

<ContextMenu>
  <ContextMenuTrigger />
  <ContextMenuContent>
    <ContextMenuGroup>
      <ContextMenuLabel />
      <ContextMenuItem />
      <ContextMenuItem />
    </ContextMenuGroup>
    <ContextMenuSeparator />
    <ContextMenuSub>
      <ContextMenuSubTrigger />
      <ContextMenuSubContent>
        <ContextMenuGroup>
          <ContextMenuItem />
        </ContextMenuGroup>
      </ContextMenuSubContent>
    </ContextMenuSub>
    <ContextMenuCheckboxItem />
  </ContextMenuContent>
</ContextMenu>

Examples


Default

A context menu with groups, shortcuts, submenus, checkbox items, and a destructive action.

API Reference

ContextMenu

The root component. Wraps the trigger and content.

ContextMenuTrigger

The area that activates the context menu on right-click or long-press.

PropTypeDefaultDescription
renderReact.ReactElement | (props, state) => React.ReactElement-Renders a custom trigger element and merges trigger props onto it.

ContextMenuContent

The popover panel that appears at the pointer position.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left"-Forces the panel to a specific side.

ContextMenuItem

A single actionable item in the menu. Extends the shared MenuItem props.

PropTypeDefaultDescription
labelReact.ReactNode-The label text or content of the item.
iconReact.ReactNode-An optional leading icon.
descstring-An optional description below the label.
variant"default" | "secondary" | "sidebar" | "warning" | "error""default"The visual style of the item.
disabledboolean-Whether the item is disabled.
onClickReact.MouseEventHandler<HTMLElement>-Handler called when the item is clicked.

ContextMenuCheckboxItem

A menu item that can be toggled on and off. Extends ContextMenuItem props.

PropTypeDefaultDescription
checkedboolean-Whether the item is checked.
onCheckedChange(checked: boolean) => void-Handler called when the checked state changes.

ContextMenuLabel

A non-interactive label used to title a group of items.

PropTypeDefaultDescription
titlestring-The group label text.

ContextMenuSeparator

A visual divider between groups of items.

ContextMenuShortcut

Displays a keyboard shortcut hint aligned to the right of an item.

ContextMenuGroup

Groups related menu items together with consistent spacing.

ContextMenuSub

Wraps a sub-menu trigger and its content.

ContextMenuSubTrigger

A menu item that opens a nested sub-menu. Accepts the same props as ContextMenuItem.

ContextMenuSubContent

The popover panel for a sub-menu.