LineaUI.Components.Dropdown (linea_ui v0.3.0)

Copy Markdown View Source

LineOne's dropdown menu: a white box under its button with links and actions, groups split by separators, icons, a header, a search field, people.

<.dropdown id="actions" label="Dropdown">
  <.dropdown_item href="#">Action</.dropdown_item>
  <.dropdown_item phx-click="archive">Archive</.dropdown_item>
  <.dropdown_separator />
  <.dropdown_item color="error" phx-click="delete">
    <:icon><svg>…</svg></:icon>
    Delete item
  </.dropdown_item>
</.dropdown>

toggle_icon draws LineOne's flat round icon button with the three dots (the menu of a card):

<.dropdown id="card-menu" toggle_icon="dots" placement="bottom-end">
  <.dropdown_item href="#">Action</.dropdown_item>
</.dropdown>

label draws LineOne's button with its turning chevron (color and shape style it); any other trigger goes in the :toggle slot:

<.dropdown id="more">
  <:toggle><.button icon variant="flat" shape="pill" aria-label="More">⋮</.button></:toggle>
  …
</.dropdown>

A dropdown_submenu nests a menu that opens to the side, on hover, on click, or with → (← or Esc goes back to its parent):

<.dropdown id="row" toggle_icon="dots">
  <.dropdown_item phx-click="edit">Edit</.dropdown_item>
  <.dropdown_submenu label="Move to">
    <.dropdown_item phx-click="move" phx-value-to="archive">Archive</.dropdown_item>
    <.dropdown_item phx-click="move" phx-value-to="trash">Trash</.dropdown_item>
  </.dropdown_submenu>
</.dropdown>

A long menu scrolls inside a scroll_area (LineaUI.Components.ScrollArea); keep submenus out of a scrolling box, which would clip them.

The keyboard works as in a menu (↑ ↓ Home End, letters, Esc, Tab). It opens and closes from the browser (LineaUI.toggle("actions")), from the server (LineaUI.close(socket, "actions")) or from open; on_open / on_close run whoever opened or closed it.

Summary

Functions

Renders a dropdown menu.

A title over the items, as in LineOne's "HTML Content" dropdown.

An item of the menu: a link with href, navigate or patch, a button otherwise (phx-click, type="submit"...). A link takes target, rel, download, hreflang and referrerpolicy, so it can open in a new tab or download a file

The search field across the menu, with LineOne's magnifier. Typing in it is not taken by the menu's keys; phx-change, phx-debounce and name pass through.

The line between two groups of items.

An item that opens a nested menu to its side, holding dropdown_items (and separators, headers, or further submenus). It opens when the pointer rests on it, on click, and with →, Enter or Space, which also move the focus into it; ← and Esc close it and give the focus back. It opens on the placement side, or the other one when the screen has no room there.

Functions