SutraUI.ContextMenu (Sutra UI v0.4.0)
View SourceA right-click and keyboard-accessible context menu.
Renders a trigger that opens a positioned menu on right-click or keyboard input. Supports nested submenus, checkboxes, radio groups, shortcuts, labels, and separators — following the shadcn/ui composition model.
Menu items accept global attributes, so LiveView actions can be attached
directly with phx-click, phx-value-*, phx-target, and the usual
Phoenix bindings.
Examples
<.context_menu id="file-menu">
<:trigger>
<div class="rounded-lg border p-4">Right-click here</div>
</:trigger>
<.context_menu_item phx-click="new-file">New File</.context_menu_item>
<.context_menu_separator />
<.context_menu_checkbox_item checked={@auto_save} phx-click="toggle-autosave">
Auto-save
</.context_menu_checkbox_item>
<.context_menu_sub>
<:trigger>Share</:trigger>
<.context_menu_item phx-click="copy-link">Copy link</.context_menu_item>
<.context_menu_item phx-click="email">Email</.context_menu_item>
</.context_menu_sub>
</.context_menu>Sub-menus
context_menu_sub renders a submenu with its own :trigger slot and item
content. Submenus open on hover (mouse) and on Right-arrow (keyboard), and
close on Left-arrow or Escape.
Accessibility
- Trigger has
aria-haspopup="menu"andaria-expanded. - Menu uses
role="menu", items userole="menuitem". - Keyboard navigation: ArrowUp/Down, Home/End, Enter/Space, Escape.
- Submenu: Right arrow opens, Left arrow / Escape closes.
- Checkbox items use
role="menuitemcheckbox"witharia-checked. - Radio items use
role="menuitemradio"witharia-checked. - Disabled items have
aria-disabled="true".
Summary
Functions
Renders a checkbox menu item with role="menuitemcheckbox".
Renders a context menu item. Pass LiveView events via phx-click on the item
or render a link/button inside the slot.
Renders a non-interactive label for a group of items.
Renders a radio menu item with role="menuitemradio".
Renders a separator between menu items.
Renders a submenu with a trigger and nested items.