Context Menu

A context menu is not a patch — it is a composition of existing patches and Domphy patterns. No new behavior is introduced; the recipe shows how to combine menu, menuItem, and state to produce a right-click menu positioned at the cursor.

How it works

State:

  • open — controls visibility
  • x, y — cursor position captured from the contextmenu event

Menu element is declared in the tree alongside the trigger area. position: fixed with reactive left/top places it at the cursor. display: none when closed keeps it out of pointer events.

Close on outside click is registered imperatively in _onMount via document.addEventListener("click", ...) and cleaned up with addHook("Remove", ...).

Trigger uses onContextMenu to capture cursor position, then sets open to true.

Key patterns used

PatternUsage
Declare in tree + hideopen state controls display and pointerEvents
Reactive styleleft/top update without re-render
_onMount + addHookRegister and clean up document click listener
menu + menuItemStyled menu list out of the box