Menu
Items with icon, shortcut and danger; submenu
A list of commands with icons, shortcuts and separators.
Highlight with the keyboard
<.menu_panel width="w-[220px]" highlight> <.dropdown_item style="--dl:0s"><:icon><.icon name="edit" /></:icon>Editar</.dropdown_item> <.dropdown_item style="--dl:1s"><:icon><.icon name="copy" /></:icon>Duplicar</.dropdown_item> <.dropdown_item style="--dl:2s"><:icon><.icon name="link" /></:icon>Compartilhar</.dropdown_item> <.dropdown_item style="--dl:3s"><:icon><.icon name="folder" /></:icon>Arquivar</.dropdown_item> <.dropdown_separator /> <.dropdown_item danger><:icon><.icon name="trash" /></:icon>Excluir</.dropdown_item> </.menu_panel>
Try it: the trigger opens the real menu
<div class="flex flex-wrap items-start gap-2.5"> <.dropdown id="menu-live-a" label="Ações" class="w-[220px]"> <.dropdown_item><:icon><.icon name="edit" /></:icon>Editar</.dropdown_item> <.dropdown_item><:icon><.icon name="copy" /></:icon>Duplicar</.dropdown_item> <.dropdown_item><:icon><.icon name="link" /></:icon>Compartilhar</.dropdown_item> <.dropdown_item><:icon><.icon name="folder" /></:icon>Arquivar</.dropdown_item> <.dropdown_separator /> <.dropdown_item danger><:icon><.icon name="trash" /></:icon>Excluir</.dropdown_item> </.dropdown> <.dropdown id="menu-live-b" label="Período" color="primary" class="w-[220px]"> <.dropdown_item>Hoje</.dropdown_item> <.dropdown_item>Últimos 7 dias</.dropdown_item> <.dropdown_item>Este mês</.dropdown_item> </.dropdown> <.dropdown id="menu-live-c" toggle_icon="dots" toggle_label="Mais ações" placement="bottom-end" class="w-[220px]"> <.dropdown_item><:icon><.icon name="edit" /></:icon>Editar</.dropdown_item> <.dropdown_item><:icon><.icon name="copy" /></:icon>Duplicar</.dropdown_item> <.dropdown_separator /> <.dropdown_item danger><:icon><.icon name="trash" /></:icon>Excluir</.dropdown_item> </.dropdown> </div> <div class="h-[220px]"></div>
Usage
<.menu><:item icon="pencil-edit-02" shortcut="E">Editar</:item>…</.menu>
Rules
- The destructive action last, separated, in
neg. - Shortcuts on the right in kbd.
API reference
Todos os function components, atributos, valores e slots que este componente cobre.
Menu lists: a vertical list of links with one active entry, plus menu_item and menu_row.
Styled only with Tailwind utilities: the list carries the look of its links (and of the active
one, marked data-state="on"), so a menu_item inside a :row takes it from the list. Every part
carries data-part (menu-list, menu-item, menu-item-count, menu-rows, menu-row...).
<.menu_list variant="solid" color="primary">
<:item navigate={~p"/orders"} active><.icon name="cart" />Orders</:item>
<:item navigate={~p"/clients"} count={12}>Clients</:item>
</.menu_list>
<.menu_list variant="pill" on_select="pick">
<:item value="shipping" active={@tab == "shipping"}>Shipping</:item>
</.menu_list>
Items with a destination (href, navigate, patch) are links; items with a value push
on_select with %{"value" => value} (a %JS{} runs instead). variant="static" with
:item slots is the read-only list (links ignore the pointer); with rows and :row it is the
canvas list of menu_rows (a div).
Streams: <.menu_list id="pages" rows={@streams.pages}><:row :let={{_id, page}}>....
Notes
- An
activelink item (ormenu_item) carriesaria-current="page". - Each
:itemaccepts any attribute (style,phx-click,id...). menu_item'svariant/colordefault tonil: the item is then a bare<a>meant for amenu_list:row; with a variant it is wrapped in its ownlu-mlnavigation.
<.menu_list>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
variant |
:string |
"link" |
link, solid, pill, gradient, bordered, static |
color |
:string |
"primary" |
primary, neutral |
on_select |
:any |
nil |
|
target |
:any |
nil |
|
rows |
:any |
nil |
A list or a stream rendered by :row. |
row_id |
:any |
nil |
|
demo |
:boolean |
false |
The animated mock: the highlight walks over the links (stagger them with style="--dl:1.5s"). |
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.
Slots:
<:item>- attrs:href,navigate,patch,active,value,count,class,style,id,title,phx-click,phx-target,phx-value-id<:row>
<.menu_item>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
variant |
:string |
nil |
nil, link, solid, pill, gradient, bordered |
color |
:string |
nil |
nil, primary, neutral |
active |
:boolean |
false |
|
value |
:string |
nil |
|
on_select |
:any |
nil |
|
target |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element, including href, navigate, patch, method, download, replace.
Slots:
<:count><:icon><:inner_block>(required)
<.menu_row>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
title |
:string |
nil |
|
sub |
:string |
nil |
|
unread |
:boolean |
false |
|
unread_label |
:string |
"Unread" |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element, including href, navigate, patch, method, download, replace.
Slots:
<:icon><:inner_block><:value>
<.menu>
Same as menu_list/1 (same attributes and slots), under the name the design vitrine uses.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
variant |
:string |
"link" |
link, solid, pill, gradient, bordered, static |
color |
:string |
"primary" |
primary, neutral |
on_select |
:any |
nil |
|
target |
:any |
nil |
|
rows |
:any |
nil |
A list or a stream rendered by :row. |
row_id |
:any |
nil |
|
demo |
:boolean |
false |
The animated mock: the highlight walks over the links. |
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.
Slots:
<:item>- attrs:href,navigate,patch,active,value,count,class,style,id,title,phx-click,phx-target,phx-value-id<:row>