Dropdown (actions menu)
A small menu of actions attached to a button. Without JavaScript the native <details> opens and closes and the items are ordinary buttons and links. With it, the menu follows the ARIA menu button pattern. This is not a navigation menu: use links, a disclosure or the drawer for that.
Couldn't load the demo. Open alone — A menu under its trigger
<details class="iv-dropdown" data-iv-component="dropdown" data-iv-placement="bottom-start">
<summary class="iv-button iv-button--secondary">Actions</summary>
<div class="iv-dropdown__menu">
<button class="iv-dropdown__item" type="button">Duplicate project</button>
<button class="iv-dropdown__item" type="button">Export as CSV</button>
<hr class="iv-dropdown__separator">
<a class="iv-dropdown__item" href="#dropdown-note">Read the retention policy</a>
</div>
</details>
<p id="dropdown-note">Exported files are kept for thirty days and then deleted from the storage bucket.</p>// data-iv-component="dropdown"
{
placement: "bottom-start",
}Options
| Option | Attribute | Default |
|---|---|---|
placement | data-iv-placement | bottom-start (bottom-end aligns to the end edge) |
closeOnSelect | data-iv-close-on-select | true |
Keyboard
Enter, Space or Down on the button opens the menu and focuses the first item; Up/Down move with wrap-around, Home/End jump; Escape closes and returns focus; Tab closes without trapping.
Events
iv:open/iv:close (cancelable) and iv:opened/iv:closed; open(), close(), toggle(), isOpen.
Common mistakes
- Using
role="menu"for a list of navigation links. - Menus with more than about seven items; use a page instead.
Without JavaScript
The served markup is a <details> whose <summary> is the trigger, so the menu opens and closes natively and every item is a working button or link. The script adds the menu-button roles, arrow keys, focus return and closing on outside clicks; destroy() puts the served HTML back.
Customising
Locals: --iv-dropdown-min-width and --iv-dropdown-offset (the gap between trigger and menu). Use iv-dropdown--end or data-iv-placement="bottom-end" when the trigger sits at the end of a row, so the menu opens inwards.
.toolbar .iv-dropdown { --iv-dropdown-min-width: 14rem; }Dropdown, select or navigation?
A dropdown runs actions: rename, duplicate, delete. To choose a value use a native select, or the picker when there are many options; to list pages use links, a disclosure or the drawer. Screen readers announce a menu as an application widget, which is wrong for a list of links.
Class index
Parts and modifiers of this family that the examples above do not show. The full list per stylesheet lives in the reference.
| Class | What it does |
|---|---|
iv-dropdown--end | Aligns the menu with the end edge of the trigger. |