SlopUI.Components.Menu (SlopUI v0.1.0)

Copy Markdown View Source

Dropdown menus built on the popover API and anchor positioning.

Summary

Functions

Wraps content with a context menu that opens on right-click (or long-press where the platform maps it to contextmenu) at the pointer, and from the keyboard with Shift+F10 or the Menu key, anchored to the focused element.

Renders a menu button and its dropdown.

A menu item. Renders a link when navigate, patch or href is set.

A non-interactive label inside a menu.

A separator between menu groups.

A submenu: a menu item that opens a nested menu beside it.

Functions

context_menu(assigns)

Wraps content with a context menu that opens on right-click (or long-press where the platform maps it to contextmenu) at the pointer, and from the keyboard with Shift+F10 or the Menu key, anchored to the focused element.

<.context_menu id="file-ctx" label="File actions">
  <.card>Right-click me</.card>
  <:menu>
    <.menu_item phx-click="open">Open</.menu_item>
    <.menu_item phx-click="rename">Rename</.menu_item>
    <.menu_separator />
    <.menu_item color="danger" phx-click="delete">Delete</.menu_item>
  </:menu>
</.context_menu>

The items support everything menu/1 items do, submenus included. Focus returns to where it was when the menu closes. The wrapper is focusable so keyboard users can open the menu even when the content has no focusable element; pass tabindex="-1" to opt out when it does.

Attributes

  • id (:string) (required)
  • label (:string) - accessible name of the menu, defaults to "Context menu". Defaults to nil.
  • tabindex (:string) - Defaults to "0".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • menu (required)
  • inner_block (required)