ContextMenu

Base class for all positioned context menus. Handles root element creation, DOM mounting, viewport-clamped positioning, outside-click dismissal, and a shared item factory. Subclass usage: 1. Call `super(title, onDismiss)` at the top of the subclass constructor. 2. Build content onto `this.root`. 3. Call `this._mount(x, y)` at the end of the subclass constructor. 4. Override `close()` if extra cleanup is needed, calling `super.close()`. Stacking usage: primaryMenu.stack(secondaryMenu) Merges secondaryMenu's title and items below primaryMenu's content. The combined result is a single mounted menu. Returns `this` for chaining.

Constructor

new ContextMenu(title, onDismissopt, infoopt)

Parameters:
NameTypeAttributesDefaultDescription
titlestringLabel shown at the top of the menu identifying what was right-clicked.
onDismissfunction<optional>
Called when the menu is dismissed via outside click.
infoObject | null<optional>
nullWhen provided, an info-widget icon is prepended to the title row. `message` is the hover tooltip text; `href` opens a docs page on click.

Classes

ContextMenu

Methods

_mount(x, y)

Appends the menu to the document body, positions it at (x, y), and starts listening for outside clicks. Call this at the end of the subclass constructor once all content has been built.
Parameters:
NameTypeDescription
xnumberPreferred left position in viewport pixels.
ynumberPreferred top position in viewport pixels.

close()

Removes the menu from the DOM. Override to add cleanup; call super.close().

makeItem(iconHtml, label, kbd, onClick, disabledReasonopt) → {HTMLElement}

Creates a standard menu item element.
Parameters:
NameTypeAttributesDefaultDescription
iconHtmlstringInner HTML for the icon cell (character or SVG/icon span).
labelstringDisplay label text.
kbdstring | nullKeyboard shortcut hint; pass null to omit.
onClickfunction | nullClick handler; pass null for disabled items.
disabledReasonstring | null<optional>
nullIf set, the item is dimmed and shows this as a tooltip.
Returns:
Type: 
HTMLElement

stack(childMenu) → {ContextMenu}

Merges `childMenu` below this menu as a stacked section. The child's title and items are appended to this root separated by a divider. The child is detached from the DOM and its lifecycle (close, dismiss) is taken over by this menu. Returns `this` for chaining.
Parameters:
NameTypeDescription
childMenuContextMenuA mounted ContextMenu instance to stack below this one.
Returns:
this
Type: 
ContextMenu