Constructor
new ContextMenu(title, onDismissopt, infoopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
title | string | Label shown at the top of the menu identifying what was right-clicked. | ||
onDismiss | function | <optional> | Called when the menu is dismissed via outside click. | |
info | Object | | <optional> | null | When 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
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:
| Name | Type | Description |
|---|---|---|
x | number | Preferred left position in viewport pixels. |
y | number | Preferred 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:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
iconHtml | string | Inner HTML for the icon cell (character or SVG/icon span). | ||
label | string | Display label text. | ||
kbd | string | | Keyboard shortcut hint; pass null to omit. | ||
onClick | function | | Click handler; pass null for disabled items. | ||
disabledReason | string | | <optional> | null | If 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:
| Name | Type | Description |
|---|---|---|
childMenu | ContextMenu | A mounted ContextMenu instance to stack below this one. |
Returns:
this
- Type:
- ContextMenu