Skip to main content

Context Menu

A context menu is activated by right-clicking (or long-pressing on touch devices) and displays a list of contextual actions or options.

Import

Basic Usage

Sub-components

Root

Groups all parts of the context menu. Doesn’t render its own HTML element. Key Props:
  • open (boolean): Whether the context menu is currently open
  • defaultOpen (boolean): Whether the context menu is initially open (default: false)
  • onOpenChange ((open: boolean, eventDetails) => void): Event handler called when the menu is opened or closed

Trigger

The element that opens the context menu on right-click or long-press.

Portal

Portals the menu content to a different part of the DOM.

Positioner

Positions the menu at the cursor position. The container for the menu content.

Item

A menu item that triggers an action when selected. Key Props:
  • onSelect (() => void): Called when the item is selected
  • disabled (boolean): Whether the item is disabled

CheckboxItem

A menu item with a checkbox. Key Props:
  • checked (boolean): Whether the checkbox is checked
  • onCheckedChange ((checked: boolean) => void): Called when the checked state changes

CheckboxItemIndicator

Visual indicator for checkbox items.

RadioGroup

Groups radio items together. Key Props:
  • value (string): The value of the selected radio item
  • onValueChange ((value: string) => void): Called when the value changes

RadioItem

A menu item with a radio button. Key Props:
  • value (string): The value of this radio item

RadioItemIndicator

Visual indicator for radio items.

Group

Groups related menu items together.

GroupLabel

A label for a menu group.

LinkItem

A menu item that renders as a link. Key Props:
  • href (string): The URL to navigate to
Groups all parts of a submenu. A menu item that opens a submenu.

Separator

A visual separator between menu items.

Arrow

An optional arrow that points to the trigger.

Backdrop

An optional backdrop element.

Styling Example

Key Features

  • Activates on right-click or long-press
  • Supports nested submenus
  • Checkbox and radio items
  • Keyboard navigation with arrow keys
  • Automatic positioning at cursor location
  • Disabled items
  • Link items for navigation
  • Group labels and separators

Accessibility

  • Has role="menu" with appropriate ARIA attributes
  • Menu items have role="menuitem", role="menuitemcheckbox", or role="menuitemradio"
  • Full keyboard navigation support (arrow keys, Enter, Space, Escape)
  • Focus management when opening/closing
  • Disabled items are marked with aria-disabled
  • Checked state is communicated via aria-checked