Dropdown

<wa-dropdown> Stable Since 2.0

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.

Dropdowns consist of a trigger and a panel. By default, activating the trigger will expose the panel and interacting outside of the panel will close it.

Dropdowns are designed to work well with dropdown items to provide a list of options the user can select from. However, dropdowns can also be used in lower-level applications. The API gives you complete control over showing, hiding, and positioning the panel.

Dropdown Cut Copy Paste Show images Show All Images Show Thumbnails Emoji Shortcuts Word Wrap Delete

Examples

Link to This Section

Getting the Selected Item

Link to This Section

When an item is selected, the wa-select event will be emitted by the dropdown. You can inspect event.detail.item to get a reference to the selected item. If you've provided a value for each dropdown item, it will be available in event.detail.item.value.

To keep the dropdown open after selection, call event.preventDefault() in the wa-select event's callback.

Showing Icons

Link to This Section

Use the icon slot to add icons to dropdown items. This works best with icon elements.

Edit Cut Copy Paste Delete

Showing Labels & Dividers

Link to This Section

Use any heading, e.g. <h1><h6> to add labels and the <wa-divider> element for separators.

Device

Type

Phone Tablet Desktop More options…

Showing Details

Link to This Section

Use the details slot to display details, such as keyboard shortcuts, inside dropdown items.

Message Reply ⌘R Forward ⌘F Move ⌘M Archive ⌘A Delete Del

Checkable Items

Link to This Section

You can turn a dropdown item into a checkable option by setting type="checkbox". Add the checked attribute to make it checked initially. When clicked, the item's checked state will toggle and the dropdown will close. You can cancel the wa-select event if you want to keep it open instead.

When a checkable option exists anywhere in the dropdown, all items will receive additional padding so they align properly.

Destructive Items

Link to This Section

Add variant="danger" to any dropdown item to highlight that it's a dangerous action.

Project Share Preferences

Danger zone

Archive Delete

Placement

Link to This Section

The preferred placement of the dropdown can be set with the placement attribute. Note that the actual position may vary to ensure the panel remains in the viewport.

File formats PDF Document Word Document Excel Spreadsheet PowerPoint Presentation Plain Text JSON File

Distance

Link to This Section

The distance from the panel to the trigger can be customized using the distance attribute. This value is specified in pixels.

Edit Cut Copy Paste Find Replace

Offset

Link to This Section

The offset of the panel along the trigger can be customized using the skidding attribute. This value is specified in pixels.

Edit Cut Copy Paste Find Replace
Link to This Section

To create submenus, nest dropdown items inside of a dropdown item and assign slot="submenu" to each one. You can also add dividers as needed.

Dropdown items that have a submenu will not dispatch the wa-select event. However, items inside the submenu will, unless they also have a submenu.

As a UX best practice, avoid using more than one level of submenu when possible.

Disabling Items

Link to This Section

Add the disabled attribute to any dropdown item to disable it.

Payment method Cash Personal check Credit card Gift card

Importing

Link to This Section

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.

CDN npm Self-Hosted React

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

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

CSS parts

Link to This Section

Learn more about CSS parts.

Dependencies

Link to This Section

This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.

Need a hand? Report a bug Ask for help
    No results