{#- chirp-ui: Context Menu Right-click (or keyboard) menu anchored at the pointer. Wrap any non-interactive region in `context_menu(items=[...])`; right-clicking inside it opens a `role="menu"` panel at the cursor with full keyboard support: ArrowUp/Down/Home/End move focus via roving tabindex, Enter/Space activate, Escape closes and returns focus to the region. When the region itself is focused, Enter/Space/ArrowDown, the ContextMenu key, or Shift+F10 open the menu. The native browser menu is suppressed inside the region. Requires Alpine.js. Items: list of dicts — {label, action?|href?, icon?, variant?, disabled?}. `variant` is one of default/danger/muted. Selecting an item dispatches `chirpui:context-menu-selected` with {label, action?, href?} (mirrors dropdown_menu). Dividers are not supported in v1 (flat item list). Accessibility: the region is a `role="button"` trigger with `aria-haspopup="menu"`; the menu panel is a SIBLING of the trigger (never nested inside it). Give the region a `label` that matches any visible call-to-action text, and keep the slotted target content non-interactive (no nested links/buttons), so the trigger button has no nested controls. Usage: from "chirpui/context_menu.html" import context_menu {% call context_menu(items=[ {"label": "Open", "action": "open", "icon": "↗"}, {"label": "Rename", "action": "rename"}, {"label": "Delete", "action": "delete", "variant": "danger"}, ], label="Right-click for actions") %}
Right-click for actions
{% end %} -#} {% def context_menu(items, label="Context menu", id="chirpui-context-menu") %}
{% slot %}
{% end %}