A right-click menu attached to a region of the page.
Right-clicking anywhere inside the trigger region opens a floating menu at
the cursor. Touch users get the same menu from a long press, and keyboard
users open it with Shift+F10 or the Menu key while focus is inside the
region. Everything outside the region keeps the browser's own context menu.
The panel is the same floating surface as dropdown/1, and the items share
its anatomy - icons in the inner block, an optional kbd hint on the right,
a danger variant for the destructive one.
Examples
The pointer path - right-click the card:
<.context_menu id="file-card">
<:trigger>
<div class="p-6 border rounded-xl">Q3-forecast.xlsx</div>
</:trigger>
<.context_menu_item link_type="button" phx-click="open" label="Open" />
<.context_menu_item link_type="button" phx-click="rename" label="Rename" />
<.context_menu_separator />
<.context_menu_item
link_type="button"
phx-click="delete"
variant="danger"
kbd="⌘⌫"
label="Delete"
/>
</.context_menu>Items take arbitrary content, so an icon is just an icon:
<.context_menu id="doc-body">
<:trigger>
<p>Right-click this paragraph.</p>
</:trigger>
<.context_menu_label>Selection</.context_menu_label>
<.context_menu_item link_type="button" phx-click="copy" kbd="⌘C">
<.icon name="hero-clipboard" class="w-4 h-4" /> Copy
</.context_menu_item>
<.context_menu_item link_type="a" to="/search" label="Search the web" />
</.context_menu>Touch and keyboard
Long-pressing the region for half a second opens the menu at the finger, and the OS text-selection callout is suppressed inside the region so the press reads as a menu gesture rather than a selection.
Keyboard users tab to the region (it is a focus stop) and press Shift+F10
or the Menu key. The menu then opens at the region with the first item
focused. Arrow keys move through the items and skip disabled ones, Home
and End jump to the ends, Enter and Space activate, Escape closes
and hands focus back to the region.
Turning it off
disabled drops the hook entirely, so right-clicking the region falls
straight through to the browser's native menu:
<.context_menu id="file-card" disabled={@read_only}>
...
</.context_menu>
Summary
Functions
The trigger region and its menu. See the module docs for the pointer, touch and keyboard paths.
One command in a context menu.
A non-interactive heading for a group of items.
A thin divider between groups of items.