Component
Dropdown
Published on
Description
The Dropdown component displays a list of links behind a toggle button. It uses the native HTML popover attribute with popovertarget for the button and CSS anchor positioning for placement, so it requires no JavaScript. The button label is set with the label prop, or replaced entirely with a button snippet for icon-only triggers. Remaining props are applied to the button; add class="chevron" for a chevron that rotates while open. The children snippet is the list itself.
In browsers without CSS anchor positioning the dropdown still opens, closes, and light-dismisses; it renders at its position in the normal flow after the button, without collision avoidance.
Example
Accessibility
- This is the WAI disclosure navigation pattern: a button plus a plain list of links, not
role="menu", which would require JavaScript arrow-key handling. - The browser sets
aria-expandedon thepopovertargetbutton automatically. - Escape and light-dismiss close the dropdown, returning focus to the button.
- The list follows the button in source order, so Tab moves from the button into the links.
- Icon-only triggers must include a
.visually-hiddenlabel inside thebuttonsnippet. - Never place a dropdown inside a larger click target. Rows that carry a dropdown use ItemList rather than a clickable Task list row, so a near-miss on the button cannot navigate away.
References
- Disclosure Navigation Menu(opens in new tab) — W3C WAI ARIA Authoring Practices
- Disclosure Widgets(opens in new tab) — Adrian Roselli
- CSS anchor positioning(opens in new tab) — MDN
Related
- Popover — the underlying overlay primitive
- Item list — non-clickable rows with a per-row dropdown
- Disclosure — for inline expandable content
Variables
None