A Dropdown presents a list of options or actions.
Preview
Usage
Use the Dropdown component when you have a list of links or actions that can be performed. Use the Select Menu component to allow the users to choose one option from the list.
- The dropdown component provides accessibility controls when using with List item component.
- The dropdown has two major pieces that are provided as required named slots: the anchor and the list.
- The anchor slot contains the element that controls the dropdown's visibility.
- The list slot contains a list of items to show as dropdown menu items.
Variants and Examples
Default
With Sections and Headings
Context Menu
Set openOnContext=true to open the menu on right-click (context menu) and disable the default trigger behavior.
Vue API
Slots
Props
Events
Accessibility
A screen reader visible only close button is added by default.
The dropdown menu has a role of "menu" and the list items have a role "menuitem". See W3C guidelines for more information.
List
The Dropdown is rendered with semantic <ul> and <li>. The list slot is wrapped in <ul> element so make sure the items are wrapped in <li> element and each item has the menuitem role. It is recommended to use the List Item component as it supports all the necessary accessibility props and interactions.
Focus & Keyboard
A dropdown menu has well defined standard keyboard interactions that it should support. The focus will be set to the the active item on keyboard navigation. UP and DOWN arrows move the highlighted selection between the list items. HOME and END keys will jump straight to the first or the last item. Once the beginning or the end of the list is reached the selection will move to the opposite end of the list by default. If you want custom behavior you can pass onBeginningOfList and onEndOfList methods as props. A-Z keys will cycle through items that start with the corresponding letter.
Pressing ESC key while the dropdown has focus will emit an escape event and will close the menu. When the highlight selection changes, a highlight event is emitted with the index of the currently highlighted item. SPACE key will open the dropdown if it's closed and select the item when it's pressed on a list item.