Context Menu

Displays a menu located at the pointer, triggered by a right-click.

Features

  • Supports items, labels, groups of items.
  • Supports checkable items (single or multiple).
  • Customise side, alignment, offsets, collision handling.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Typeahead support.
  • Dismissing and layering behavior is highly customizable.

Install the component from your command line.

Import the components and piece the parts together.

Create your styled context menu component from the primitive parts.

Right click anywhere

Adheres to the Menu WAI-ARIA design pattern and uses roving tabindex to manage focus movement among menu items.

Contains all the parts of a context menu.

The area that opens the context menu. Wrap it around the target you want the context menu to open from when right-clicking (or using the relevant keyboard shortcuts).

PropTypeDefaultRequired
asenumspan

The component that pops out in an open context menu.

PropTypeDefaultRequired
asenumdiv
disableOutsidePointerEventsbooleantrue
onEscapeKeyDownfunction
onPointerDownOutsidefunction
onInteractOutsidefunction
forceMountboolean
sideenum"bottom"
sideOffsetnumber0
alignenum"center"
alignOffsetnumber0
avoidCollisionsbooleantrue
collisionToleranceboolean0

The component that contains the context menu items.

PropTypeDefaultRequired
asenumdiv
disabledboolean
onSelectfunction
textValuestring

Used to group multiple ContextMenu.Items.

PropTypeDefaultRequired
asenumdiv

Used to render a label. It won't be focusable using arrow keys.

PropTypeDefaultRequired
asenumdiv

An item that can be controlled and rendered like a checkbox.

PropTypeDefaultRequired
asenumdiv
checkedboolean
onCheckedChangefunction
disabledboolean
onSelectfunction
textValuestring

Used to group multiple ContextMenu.RadioItems.

PropTypeDefaultRequired
asenumdiv
valuestring
onValueChangefunction

An item that can be controlled and rendered like a radio.

PropTypeDefaultRequired
asenumdiv
valuestring
disabledboolean
onSelectfunction
textValuestring

Renders when the parent ContextMenu.CheckboxItem or ContextMenu.RadioItem is checked. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.

PropTypeDefaultRequired
asenumspan
forceMountboolean

Used to visually separate items in the context menu.

PropTypeDefaultRequired
asenumdiv

We expose a CSS custom property --radix-context-menu-content-transform-origin. Use it to animate the content from its computed origin based on side, sideOffset, align, alignOffset and any collisions.

We expose data-side and data-align attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.

You can add special styles to disabled items via the data-disabled attribute.

Right click anywhere

Use the Separator part to add a separator between items.

Right click anywhere

Use the Label part to help label a section.

Right click anywhere

Use the CheckboxItem part to add an item that can be checked.

Right click anywhere

Use the RadioGroup and RadioItem parts to add an item that can be checked amongst others.

Right click anywhere
Right click anywhere
KeyDescription
SpaceActivates the focused item.
EnterActivates the focused item.
ArrowDownMoves focus to the next item.
ArrowUpMoves focus to the previous item.
EscCloses Content.