Right-click this workspace block
Inspect spacing, shortcuts, separators, and the destructive row in the same menu.
Installation
npx shadcn@latest add @iconiq/context-menuProps
ContextMenu
4 props
Stateful wrapper that listens for the native contextmenu event on a local surface and renders a fixed-position floating menu.
items
ContextMenuItem[]Required
Ordered list of menu rows. Each item defines its own label, optional icon and shortcut, click handler, and row state.
children
ReactNodeRequired
Content wrapped by the local context-click target. The component always renders a div around this content and attaches the right-click handler there.
className
stringMerged onto the wrapper div that receives the native context menu event.
menuClassName
stringMerged onto the floating motion.div for local surface styling overrides. The component still applies an inline width of 232px.
Notes
Open state is fully internal. This implementation does not expose controlled open props, state callbacks, or an imperative API.
The menu opens only from the native contextmenu event, then flips horizontally or vertically when the estimated panel would overflow the viewport.
Closing is handled internally on outside mousedown, scroll, resize, and Escape. ArrowUp and ArrowDown move the highlighted row in local state, but DOM focus does not move into the menu.
ContextMenuItem
7 props
Data shape used by the items prop to define each row in the menu.
label
stringRequired
Primary row copy rendered as the main action label.
icon
ReactNodeOptional leading visual rendered inside the fixed 16px icon slot.
shortcut
stringOptional trailing helper text, typically a keyboard hint such as R or Cmd+D.
onSelect
() => voidCalled when the row is activated with a click or Enter on the currently highlighted item.
destructive
booleanSwitches the row into the destructive color treatment and changes the active highlight tint.
disabled
booleanDims the row and blocks pointer and Enter selection.
separatorAfter
booleanInserts a thin divider after the row unless it is already the last rendered item.
Notes
Keyboard navigation skips disabled rows in both directions. If every row is disabled, the highlighted index stays unchanged.