A menu opened from an area at the pointer, by a right-click, a long press or the ContextMenu key, built on Menu's parts, in each framework.
A menu of actions opened from an area of the page: a right-click opens it at the pointer, a
touch long press at the finger, and the ContextMenu key or Shift+F10 at the focused element.
Its content is a Menu's: items, groups, separators, checkbox and radio items,
submenus. The menu follows the WAI-ARIA APG
menu pattern (roles, keys, roving focus); the
APG has no context menu pattern of its own, so its opening follows Base UI and the platforms. A
menu opened by a button is a Menu.
ContextMenu has its own entry and is built on Menu's parts, whose part attribute names the
context menu (context-menu-item). Only its Root and its Trigger area are its own.
Right-click on the area, or on an element inside it: the browser's menu is prevented and
the menu opens with its popup's corner at the pointer (reason trigger-press), the popup
focused and no item highlighted. The mouseup that ends the right-click activates nothing: an
item activates on a click only. A right-click on the area while the menu is open closes it (an
outside press) and opens it again at the new point.
Touch long press: a touch held still on the area for 500 ms opens it at the press point
(trigger-press). A move beyond 10 px, a release or a cancel before then opens nothing; the
click and the contextmenu that follow a long press are ignored. Mouse and pen long presses do
nothing.
Keyboard: the ContextMenu key or Shift+F10, with focus on the area or inside it, opens the
menu anchored at the focused element with the first item highlighted (list-navigation). The
browser's own contextmenu after the key neither reopens it nor shows the browser's menu.
Inside: every key and pointer rule is Menu's: arrows, Home and End, typeahead, Enter and
Space, checkbox and radio items, submenus with their safe area. A contextmenu inside the menu
is prevented and does nothing.
Close: Escape closes one level (escape-key), an item closes them all (item-press), a
press outside closes them all (outside-press), Tab closes them all (focus-out) and moves on
from the element that had focus when it opened. Focus returns to the element that had focus
when the menu opened (a right-click focuses the focusable element it presses), when it is still
in the page and not disabled; else focus does not move.
Positioning: the root level is anchored to a point (a virtual anchor),
side="bottom" align="start" with no offset: its start corner is at the point, flipped and
shifted to stay in the viewport. In RTL its start corner is its right edge. It does not follow
the page's scroll.
Modal (modal, off by default): as Menu's, the page does not scroll and the pointer
outside is blocked while open.
Lifecycle: onOpenChange before the change (details.cancel() keeps it as it is),
onOpenChangeComplete(open), the actions close() and unmount(), and the Portal's
keepMounted, as every overlay's. A context menu has one Trigger area: no handle and no
triggerId.
No button names the popup: give it an aria-label. Turn off text selection and the system
callout of a long press in your styles (user-select: none, -webkit-touch-callout: none).
Every part also takes what the primitive contract gives. The
names below are React's; Vue binds them the same way (v-model:open, @open-change), and Angular
as inputs and outputs ([(open)], (openChangeDetails)). The parts after the Trigger are
Menu's.
every change, with its reason (trigger-press, list-navigation, item-press, escape-key, outside-press, focus-out); details.trigger is the area; called before the change, details.cancel() stops it
onOpenChangeComplete
(open: boolean) => void
once an opening or a closing has finished its transitions
actionsRef (react)
{ current: OverlayActions | null }
receives close() (reason imperative-action) and unmount(); Vue exposes them on the Root's template ref, Angular as the root directive's methods
loopFocus
boolean
true
the arrow keys wrap at the ends
modal
boolean
false
locks the page's scroll and blocks the pointer outside while open
disabled
boolean
false
the area opens nothing, and the browser's own menu shows
data-popup-open while the menu is open, data-disabled; no role, no aria-haspopup and no inline style (it is an area, not a button)
Positioner
role="presentation", data-side, data-align, data-open / data-closed, data-nested (a submenu); hidden while kept mounted and closed
Popup
role="menu", aria-orientation="vertical", tabindex="-1", data-side, data-align, data-open / data-closed, data-starting-style, data-ending-style; no aria-labelledby on the root level (give it an aria-label); a submenu's is labelled by its SubmenuTrigger and carries data-nested