Dropdown
Dropdowns display a list of options triggered by a button or other element. They support keyboard navigation, submenus, and checkable items for building menus and context actions.
A dropdown pairs a trigger with a panel: activating the trigger opens the panel, and interacting outside it closes the panel. Most dropdowns hold dropdown items, but the API also gives you direct control over showing, hiding, and positioning the panel for lower-level uses.
Examples
Showing Icons
Use the icon slot to add an icon before a dropdown item's label. This works best with icon elements.
Showing Labels & Dividers
Use any heading (<h1>–<h6>) to label a group of items, and the <wa-divider> element to separate them.
Type
Showing Details
Use the details slot to show secondary content after the label, such as a keyboard shortcut.
Checkable Items
Set type="checkbox" to turn a dropdown item into a toggle, and add checked to start it on. Selecting a checkable item flips its checked state and closes the dropdown; cancel the wa-select event to keep it open instead.
When any item is checkable, every item in the dropdown gains matching padding so labels stay aligned.
Destructive Items
Set variant="danger" on a dropdown item to flag a destructive action like deleting.
Danger zone
Submenus
To nest a menu, place dropdown items inside another item with slot="submenu". Add dividers between groups as needed.
An item that opens a submenu won't emit wa-select itself. Items inside the submenu do, unless they open a submenu of their own.
Avoid nesting more than one level of submenu.
Deeply nested menus are hard to navigate, especially with a pointer. Flatten the structure or move secondary choices into a separate view when you can.
Disabled
Add disabled to any dropdown item to make it unselectable.
Placement
Set the placement attribute to control where the panel opens relative to the trigger. The panel shifts to a more optimal spot when the preferred placement doesn't have room.
| Placement | Opens |
|---|---|
bottom-start |
Below the trigger, aligned to its start edge |
bottom, bottom-end |
Below the trigger, centered or aligned to the end edge |
top, top-start, top-end |
Above the trigger |
right, right-start, right-end |
To the right of the trigger |
left, left-start, left-end |
To the left of the trigger |
Distance
Set the distance attribute to change the gap between the panel and the trigger, in pixels.
Offset
Set the skidding attribute to slide the panel along the trigger, in pixels.
Reacting to Selections
When an item is selected, the dropdown emits the wa-select event. Inspect event.detail.item for the selected dropdown item; if you set a value on each item, read it from event.detail.item.value.
To keep the dropdown open after a selection, call event.preventDefault() in the wa-select handler.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/dropdown/dropdown.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/dropdown/dropdown.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/dropdown/dropdown.js';
To import this component for React 18 or below, use the following code:
import WaDropdown from '@awesome.me/webawesome/dist/react/dropdown/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The dropdown's items, typically <wa-dropdown-item> elements. |
trigger
|
The element that triggers the dropdown, such as a <wa-button> or <button>. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
distancedistance |
The distance of the dropdown menu from its trigger.
Type
number
Default
0
|
|
openopen |
Opens or closes the dropdown.
Type
boolean
Default
false
|
|
placementplacement |
The placement of the dropdown menu in reference to the trigger. The menu will shift to a more optimal location if
the preferred placement doesn't have enough room.
Type
'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'right'
| 'right-start'
| 'right-end'
| 'left'
| 'left-start'
| 'left-end'
Default
'bottom-start'
|
|
sizesize |
The dropdown's size.
Type
'xs' | 's' | 'm' | 'l' | 'xl' | 'small' | 'medium' | 'large'
Default
'm'
|
|
skiddingskidding |
The offset of the dropdown menu along its trigger.
Type
number
Default
0
|
Events
Learn more about events.
| Name | Description |
|---|---|
wa-after-hide |
Emitted after the dropdown has been hidden. |
wa-after-show |
Emitted after the dropdown has been shown. |
wa-hide |
Emitted when the dropdown is about to hide. |
wa-select |
Emitted when an item in the dropdown is selected. |
wa-show |
Emitted when the dropdown is about to show. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--hide-duration |
The duration of the hide animation.
|
--show-duration |
The duration of the show animation.
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
menu |
The dropdown menu container. |
::part(menu)
|
base |
Deprecated. Style the host element instead. |
::part(base)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.