Client component

Context Menu

A Menu opened by right-click and anchored at the pointer instead of a trigger button. Everything else is Menu: the same items, roving focus, typeahead, Escape/outside dismissal and styling.

Import#

import { ContextMenu } from "astralis-ui";

How it anchors#

Right-clicking places an invisible 1px anchor at the pointer and opens the menu against it. A right-click somewhere else first dismisses (outside pointer-down), then reopens fresh at the new position, matching platform context-menu behavior.

Props#

Menu's props, minus side and align, because the pointer is the anchor:

PropTypeDefaultDescription
open · defaultOpen · onOpenChangeboolean · boolean · (open: boolean) => voidNone · false · NoneControlled / initial state, and the change callback.
sideOffsetnumber2Gap between the pointer and the menu, in pixels.
closeOnSelectbooleantrueCloses the menu after an item is activated.

Parts#

PropTypeDefaultDescription
ContextMenu.Triggerchildren: ReactElementNoneWraps the element that opens the menu on right-click. Make it focusable for keyboard users.
ContextMenu.Content / Item / Label / Separator / Groupas on MenuNoneIdentical to Menu's parts, including Item's onSelect, icon, shortcut and danger.

Keyboard#

The menu opens from the browser's contextmenu event, which the keyboard fires too. For that to work the trigger element has to be focusable, as the area in the demo above is.

KeyAction
Shift+F10 / Menu keyOpen the menu from the focused trigger
↑ ↓Move focus between items (wraps)
Home / EndFirst / last item
type charactersJump to the item starting with what you typed
Enter / SpaceActivate the focused item
EscClose
TabClose