Dropdown Menu
Dropdown patterns with icons, submenus, and checkmarks. Keyboard accessible with ARIA menu semantics.
Overview
The dropdown component uses the <dropdown-wc> 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 <dropdown-wc> element accepts these data attributes:
| Attribute | Values | Description |
|---|---|---|
data-position |
top-start top-endbottom-start bottom-endleft-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 dropdown-wc elements for submenus. Use data-position="right-start" for proper positioning.
Event Handling
Listen for dropdown events to respond to user actions.
Usage Notes
- Accessibility: Use
visually-hiddentext 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