drop-down

Accessible dropdown menus with keyboard navigation, focus management, and automatic positioning.

Overview

The <drop-down> component provides an accessible dropdown menu. It handles all keyboard interactions (arrow keys, Escape, Enter), click-outside-to-close, and proper ARIA attributes.

Attributes

AttributeValuesDefaultDescription
position"bottom-start", "bottom-end", "top-start", "top-end"bottom-startMenu position relative to trigger
hoverbooleanOpen on hover/focus instead of click (useful for nav menus)
no-flipbooleanDisable automatic flip when menu overflows viewport
open (reflected)booleanReflected state — set by open()/close()/toggle() methods, not intended as initial markup

Required Structure

ElementRequiredDescription
<button data-trigger> or <a data-trigger>yesTrigger element that opens the menu
<menu>yesMenu container with <li> items holding <button> or <a> actions

Child Attributes

AttributeOnValuesDescription
data-triggerbutton | abooleanMarks the element that opens the menu. Falls back to first <button> if absent.

Keyboard Navigation

Full keyboard support following WAI-ARIA menu pattern:

Key Action
Enter / Space Open menu (on trigger) or activate item (in menu)
ArrowDown Open menu and focus first item, or move to next item
ArrowUp Open menu and focus last item, or move to previous item
Home Focus first menu item
End Focus last menu item
Escape Close menu and return focus to trigger
Tab Close menu and move focus to next element

Position Variants

Control menu alignment with the position attribute.

Menu with Separators

Use role="separator" on empty list items to create visual dividers.

Destructive Actions

Add the danger class to highlight destructive actions.

With Links

Menu items can be links instead of buttons for navigation.

JavaScript API

Control the dropdown programmatically:

Accessibility

  • Trigger has aria-haspopup="menu" and aria-expanded
  • Menu has role="menu"
  • Menu items have role="menuitem"
  • Separators have role="separator"
  • Full keyboard navigation per WAI-ARIA menu pattern
  • Focus returns to trigger on close
  • Click outside or Escape closes menu