ContextMenu
Open item-specific actions at a context interaction point.
Use ContextMenu for actions tied to a specific surface or item at the pointer location. Keep essential actions discoverable through another visible path.
Basic usage#
Playground#
Anatomy#
Content is portaled; grouped items use the same item subtree as ungrouped items.
Usage#
Triggering the menu#
Wrap the target with ContextMenu.Trigger. The menu opens from a context-menu gesture, keyboard context-menu keys, or a supported touch/pen long press. Avoid putting essential actions only in a context menu.
Item models#
Groups, separators, checkbox items, radio items, disabled items, and nested children are all represented in the public item model. Keep state for checkbox and radio values in the application and update it through item callbacks.
Keyboard interaction#
| Key | Description |
|---|---|
| Shift + F10 / ContextMenu | Opens from a focused trigger when the trigger supports it. |
| ↓ / ↑ | Moves the active item through available menu entries. |
| → | Opens an available submenu from its parent item. |
| ← | Returns from a submenu to its parent menu. |
| ↵ / Space | Activates the current menu item. |
| Esc | Closes the current menu layer. |
Examples#
File actions#
Move a file between folders, add it to favorites, or move it to the trash and undo. These actions update local example state; permission-dependent actions remain disabled.
Checkbox and radio items#
Submenus#
Touch long press#
Attributes#
data-closedSlot: context-menu-trigger, context-menu-contentDescription: Present when disclosure or transition content is closed.data-disabledSlot: context-menu-trigger, context-menu-itemDescription: Present when the component, slot, or item is disabled.data-expandedSlot: context-menu-trigger, context-menu-content, context-menu-itemDescription: Present when the panel, accordion, or menu is expanded.data-alignSlot: context-menu-contentDescription: Stores the resolved alignment of positioned content.data-sideSlot: context-menu-contentDescription: Stores the resolved floating or drawer content side.data-destructiveSlot: context-menu-itemDescription: Present when the action has destructive semantics.data-highlightedSlot: context-menu-itemDescription: Present when the item is highlighted by pointer or keyboard navigation.data-selectedSlot: context-menu-itemDescription: Present when the item or tab is selected.Props#
ContextMenu#
Trigger#
Renders a <div> element by default.
Content#
Props for the ContextMenu component. Renders a <div> element by default.