Dropdown Menu
A button that opens an application menu. It is a compound family composed over the shared Dropdown Panel base, running the web component in menu mode — so the roving tabindex, typeahead, submenu arrows, outside-press dismissal and focus return come from the component rather than from 300 lines of ported machinery.
This one really is an ARIA role="menu", which is the opposite of Menubar's disclosure stance. The difference is that the component now implements the model those roles promise: one tab stop, arrows with wrap, Home/End, typeahead, Enter and Space activation, Tab to close, and Escape one level at a time. So the piece authors no roles at all — it would only be overwriting them.
Last selection: nothing yet
Installation
Copy the family into your app. It pulls the shared dropdown-panel base along with it:
puzzle add piece dropdown-menu
That base has a runtime dependency — the web component it wraps. Menu mode is 2.1.0's, so the range matters:
npm install @magic-spells/dropdown-panel
Then merge its stylesheets into your app's style entry. The first is required; the second adds the entrance effects and the drawn trigger arrow:
/* app/styles/styles.css */ @import "tailwindcss"; @import "@magic-spells/dropdown-panel/css" layer(components); /* required */ @import "@magic-spells/dropdown-panel/css/effects" layer(components); /* optional */
Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import DropdownMenu from '@/components/ui/DropdownMenu';
<DropdownMenu @select={ onSelect }>
<DropdownMenu.Trigger>Options</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
<DropdownMenu.Label>Account</DropdownMenu.Label>
<DropdownMenu.Item value="profile" @press={ run }>
Profile<DropdownMenu.Shortcut>⌘P</DropdownMenu.Shortcut>
</DropdownMenu.Item>
<DropdownMenu.Link href="/docs">Documentation</DropdownMenu.Link>
<DropdownMenu.Separator />
<DropdownMenu.Item value="delete" variant="danger" @press={ run }>
Delete account
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu>Trigger, Content and Sub must be direct children of the root — the component resolves them with a child selector. A loop inside a Content is fine; it is one level further down.
Two callbacks, both firing on the same activation: @press on the row is the local hook, and @select on the root sees every row including a submenu's — a choice in a Sub closes the whole chain and returns focus to the root trigger, so the root is what reports it. Return false from @select to cancel the close.
Trigger variants
Keyboard
All of it lives in the web component's menu mode; this family adds no key handling of its own, and authors no role, tabindex or aria-* attribute.
Enter / SpaceOn the trigger: open the menu and focus the first row. On a row: activate it — Space clicks a Link too, which Space alone would never follow.ArrowDown / ArrowUpOn a closed trigger: open and focus the first (or last) row. Inside an open menu: move row focus, wrapping at the ends and skipping disabled rows, separators and labels.Home / EndFirst / last row.a–zTypeahead: jump to the next row whose text starts with what you type. The buffer clears after 500 ms, and repeating one letter cycles the rows starting with it.ArrowRight / ArrowLeftOpen a Sub's panel and focus its first row; ArrowLeft closes it again and returns focus to its trigger, with the parent still open.EscapeClose one level and focus its trigger. Only the innermost open menu answers.TabCloses the menu and moves on. This is the menu pattern parting company with a plain disclosure, and it only happens because the piece opted into menu mode.Reference
DropdownMenu
The root: the host the panel positions against, and the one place @select reports.
trigger'click' (default) | 'hover' | 'both'. A dropdown menu is a menu-button, not a hover menu.arrow'none' (default) | 'flip' | 'static' — for a trigger carrying the arrow hook. Effects stylesheet only.openOptional-controlled and edge-triggered, forwarded to the base.effect'fade' | 'slide' | 'scale' | 'blur' | 'swing'. Needs the effects stylesheet.classMerged onto the host, after the load-bearing `inline-block relative`.@show / @hideFired when THIS menu opens or closes; a Sub's are filtered out.@selectValue-first: select(value, event). Fires once per activation, submenus included. Return false to cancel the close.DropdownMenu.Trigger
The control. Keep its content non-interactive — this element IS the button.
variant'button' (default) — a bordered pill; 'item' — a submenu row inside a Sub; 'bare' — no chrome, bring your own.labelThe fallback body text. Ignored the moment you put content between the tags — a filled body replaces the stock chrome entirely, so a custom trigger needs its own accessible name.classMerged onto the trigger, after the variant chrome.DropdownMenu.Content
The panel. The component stamps role="menu" on it and collects its rows as menuitems.
align'start' (default) | 'end' for a menu near the right edge.opens'down' (default) | 'right' for a Sub's panel.flipOpt in to opening upward when the panel would run past the bottom of the viewport.effect'fade' | 'slide' | 'scale' | 'blur' | 'swing'. Needs the effects stylesheet.classMerged onto the panel. Merging is not precedence: use the ! suffix (mt-1!) to override a default. Never overflow-hidden — it clips a Sub.DropdownMenu.Item
An action row — a real button. Activating it closes the chain; nothing in the piece does that, the select contract does.
valuePassed to @press, and read back by the root @select as the row value.variant'default' | 'danger' for a destructive tint.disabledGreys the row out, swallows the press, and takes it out of the arrow walk and typeahead.classMerged onto the row, after the chrome.@pressValue-first: press(value). Named apart from `value` — a callback whose name equals a prop name collides in the same props object.DropdownMenu.Link
Item's twin as a real <a>, for a row that navigates. Space activates it, which is menu mode's doing.
hrefThe destination. Reported as the row value when there is no `value`.valuePassed to @press.variant'default' | 'danger'.disabledaria-disabled plus the muted treatment; the press is swallowed and the row leaves the keyboard walk.@pressA hook fired before navigation — it cannot cancel the visit.DropdownMenu.Sub
A submenu: the nested host a Trigger + Content pair need. An Item is a <button> and cannot contain one.
trigger'both' (default) | 'hover' | 'click'. Hover or ArrowRight opens it.effect'fade' | 'slide' | 'scale' | 'blur' | 'swing'.classMerged onto the host, after the load-bearing `block`.DropdownMenu.Group · Label · Separator · Shortcut
A role="group" cluster with an aria-label, a non-interactive heading, a hairline with role="separator", and the <kbd> hint an Item pushes to its trailing edge. None of them match the item selector, so the arrows step over all four.
labelGroup only: the cluster's accessible name.classEach takes a class merged onto its element.