Skip to content

addContextMenu

addContextMenu(opts): void

Defined in: components/menu.ts:312

Attaches a context menu to the current element: adds a contextmenu handler via A so a floating menu opens (instead of the browser’s own menu) on right-click or long-press. The menu is anchored to the element and closes on Escape, Tab, item selection, or any click outside.

ContextMenuOptions

void

import * as icons from "staffa/icons";
S.box(() => {
A("#Right-click / long-tap me!");
S.addContextMenu({
items: [
{ label: "AI something", icon: icons.sparkles, click: () => ai() },
{ label: "Launch missiles", icon: icons.rocket, click: () => launch() },
],
});
});