Dropdown menu: a button (or any trigger) that opens a floating menu of links and actions.
<.dropdown id="actions" label="Ações">
<.dropdown_item phx-click="edit"><:icon><.icon name="edit" /></:icon>Editar</.dropdown_item>
<.dropdown_separator />
<.dropdown_item danger phx-click="delete">Excluir</.dropdown_item>
</.dropdown>
<.dropdown id="row" toggle_icon="dots" toggle_label="Mais ações" placement="bottom-end">
<.dropdown_item href="#">Abrir</.dropdown_item>
</.dropdown>Markup
The root is the lu-anc anchor; the menu is span.fl.p-<placement> holding the lu-pop
box. Everything dynamic (open state, ARIA, positioning, keys, click outside, scroll
following, flipping) is done by the hook LedgerUI.Dropdown
(priv/static/ledger_ui/hooks/dropdown.js), which puts the menu in the top layer
(popover="manual", position: fixed) under the trigger. The server renders the ARIA and the
initial state: popover="manual" on the menu, role="menu" on the box, role="menuitem"
(menuitemcheckbox/menuitemradio, separator) on the parts and, on the built-in triggers,
aria-haspopup="menu", aria-expanded and aria-controls; the hook only flips
aria-expanded and the open state. A custom :toggle slot receives those trigger attributes
as its argument (<:toggle :let={t}><button {t}>...</button></:toggle>); when it does not
spread them the hook falls back to setting aria-haspopup/aria-controls on that trigger.
Options that differ from the defaults reach the hook as data-*
attributes on the root (data-offset, data-hover, data-keep-submenus,
data-close-on-select, data-on-open, data-on-close).
LedgerUI.open/close/toggle work with the dropdown id.
Additions to the design README
menu_style- inline style of the menu box (width:220px);anchor_class- extra classes of the root.:overlayslot - extra content after the menu inside the anchor (a demo cursor).dropdown_itemacceptsdanger,selectedand a:trailingslot.
Summary
Functions
Attributes
id(:string) (required)label(:string) - Defaults tonil.color(:string) - Defaults to"neutral". Must be one of"neutral","primary","secondary","info","success","warning","error", or"mono".toggle_icon(:string) - Defaults tonil.Must be one ofnil,"","dots", or"dots-vertical".toggle_class(:any) - Defaults tonil.toggle_label(:string) - Defaults to"Menu".shape(:string) - Defaults tonil.Must be one ofnil,"","rounded","pill", or"square".control(:boolean) - Defaults tofalse.open(:boolean) - Defaults tofalse.hover(:boolean) - Defaults tofalse.placement(:string) - Defaults to"bottom-start". Must be one of"bottom-start","bottom","bottom-end","top-start","top","top-end","left-start","left","left-end","right-start","right", or"right-end".offset(:integer) - Defaults to4.close_on_select(:boolean) - Defaults totrue.keep_submenus(:boolean) - Defaults tofalse.on_open(:any) - Defaults tonil.on_close(:any) - Defaults tonil.target(:any) - Defaults tonil.class(:any) - Merged into the menu box. Defaults tonil.menu_style(:string) - Defaults tonil.anchor_class(:any) - Extra classes of thelu-ancroot. Defaults tonil.- Global attributes are accepted.
Slots
action- Accepts attributes:href(:string)navigate(:string)patch(:string)type(:string)disabled(:boolean)class(:any)id(:string)phx-click(:any)phx-target(:any)phx-value-id(:any)
inner_block(required)toggletrigger- The label of the button that opens the menu, as markup (instead oflabel).overlay
Attributes
checked(:boolean) - Defaults tofalse.name(:string) - Defaults tonil.value(:string) - Defaults to"true".id(:string) - Defaults tonil.count(:any) - Defaults tonil.disabled(:boolean) - Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["form"].
Slots
inner_block(required)
Attributes
subtitle(:string) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Attributes
color(:string) - Defaults to"neutral". Must be one of"neutral","primary", or"error".variant(:string) - Defaults to"default". Must be one of"default", or"media".disabled(:boolean) - Defaults tofalse.shortcut(:string) - Defaults tonil.type(:string) - Defaults to"button".danger(:boolean) - Defaults tofalse.selected(:boolean) - Check mark at the end. Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["href", "navigate", "patch", "method", "replace", "download", "target", "rel", "hreflang", "referrerpolicy", "form", "name", "value"].
Slots
icontrailinginner_block(required)
Attributes
class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Attributes
checked(:boolean) - Defaults tofalse.name(:string) - Defaults tonil.value(:string) - Defaults to"true".id(:string) - Defaults tonil.count(:any) - Defaults tonil.disabled(:boolean) - Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["form"].
Slots
inner_block(required)
Attributes
placeholder(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:string) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["phx-debounce", "phx-throttle", "autocomplete", "form"].
Attributes
class(:any) - Defaults tonil.- Global attributes are accepted.