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.

<ContextMenu><ContextMenuTrigger>  Right click here</ContextMenuTrigger><ContextMenuContent>  <ContextMenuGroup>    <ContextMenuLabel>Actions</ContextMenuLabel>    <ContextMenuItem Body="Back">      <ContextMenuShortcut>⌘[</ContextMenuShortcut>    </ContextMenuItem>    <ContextMenuItem Body="Reload">      <ContextMenuShortcut>⌘R</ContextMenuShortcut>    </ContextMenuItem>  </ContextMenuGroup>  <ContextMenuSeparator />  <ContextMenuCheckboxItem checked Body="Show Bookmarks" /></ContextMenuContent></ContextMenu>

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
asChildboolean-Merges props onto the child element instead of rendering a wrapper.

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
BodyReact.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.
onSelect(event: Event) => void-Handler called when the item is selected.

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.

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.