Dropdown
A button that opens a floating panel of links or content.
Default
Account
{ui dropdown,
title: 'Account',
triggerClass: 'button-outline',
}
{ui menu,
items: [
[
'title' => 'Profile',
'href' => '#',
'icon' => 'user',
],
[
'title' => 'Settings',
'href' => '#',
'icon' => 'settings',
],
[
'title' => 'Mail',
'href' => '#',
'icon' => 'mail',
],
],
/}
{/ui}
A dropdown is a native details: the summary is a button, and the panel floats below it. The tag's content fills the panel, and a menu is the usual content, so it takes the same entries, pages included. title and icon set the trigger the way they do on a button, and triggerClass adds classes to it, such as button-outline.
There is no open state to track. The shared ui.js closes an open dropdown on Escape, handing focus back to the trigger, on a click outside it, and when a link or button inside it is chosen.
Your own content
Invite
{ui dropdown, title: 'Invite', align: 'end'}
<div class="flex w-64 flex-col gap-3 p-2">
{ui field, name: 'email', label: 'Email'}
{ui input, name: 'email', type: 'email' /}
{/ui}
{ui button, title: 'Send invite' /}
</div>
{/ui}
The panel holds anything, not only a menu, so a dropdown can hold a form or any other element. align: 'end' opens the panel from the trigger's right edge, which keeps it on screen when the dropdown sits at the right of the page.
From pages
Components
{ui dropdown, title: 'Components'}
{ui menu, items: p('docs/ui/components')->children() /}
{/ui}
src is a URL that returns the panel's content, such as "{$page->url()}:actions". It loads once, the first time the dropdown opens, and a spinner shows in the panel until then. Declare what the URL returns as a {define actions}, which never renders in the page itself. Without JavaScript the panel stays on its placeholder, so content that must work without it is rendered directly.