Dropdown Menu

Dropdown patterns with icons, submenus, and checkmarks. Keyboard accessible with ARIA menu semantics.

Overview

The dropdown component uses the <drop-down> web component with native <menu> elements. It provides keyboard navigation, focus management, and proper ARIA roles for accessibility.

Key features:

  • Keyboard navigation with arrow keys
  • Escape key closes dropdown
  • Click outside closes dropdown
  • Support for icons and separators
  • Multiple placement options
  • Nested submenus

Basic Dropdown

A simple dropdown with action items and a separator before destructive action.

Dropdown with Icons

Add icons to menu items for visual context. Use an icon-only trigger with visually-hidden text for accessibility.

User Account Dropdown

A common pattern for user account menus with avatar and chevron indicator.

Configuration

The <drop-down> element accepts these attributes:

Attribute Values Description
position top-start top-end
bottom-start bottom-end
left-start right-start
Position of the dropdown relative to trigger. Default is bottom-start.

Trigger Button

Mark the trigger button with data-trigger:

Attribute Description
data-trigger Marks the button that opens the dropdown (required).

Nested Submenus

Nest drop-down elements for submenus. Use position="right-start" for proper positioning.

Event Handling

Listen for dropdown events to respond to user actions.

Usage Notes

  • Accessibility: Use visually-hidden text for icon-only triggers
  • Separators: Use <li role="separator"> to group related items
  • Danger actions: Add class="danger" for destructive actions
  • Keyboard: Arrow keys navigate, Enter/Space select, Escape closes
  • Placement: The dropdown auto-adjusts if there isn't enough space

Related

Dropdown WC

Web component documentation

Modal Dialog

Modal dialog patterns