Select-Only Combobox
A select-only combobox allows users to select a single option from a dropdown list. It can be used whenever users must choose from a known, limited set of predefined values. It does not allow freeform text entry.
Accessibility Features
- The trigger element must have its own visible
<label>, associated via matchingforandidattributes. - The role and state of the trigger element and options must be communicated programmatically to screen readers.
- Space and Enter expand and collapse the combobox when the trigger element is focused.
- Up Arrow and Down Arrow navigate between options, and Space and Enter select one.
- Esc collapses the dropdown and returns focus to the trigger.
- Tab moves focus away from the dropdown and collapses it automatically.
- Home and End move focus to the first and last option.
Select Element
The native <select> element handles keyboard support, screen reader announcements and dropdown behavior automatically. Using it is recommended when possible. However, its styling is limited across browsers, which is why some may prefer a custom implementation. Note that the <select> element only behaves as a combobox if it does not have the multiple attribute or a size attribute set to a value greater than 1.
Example
Code Snippet
Custom Select-Only
A custom implementation may be necessary when the desired visual design cannot be achieved with the native <select> element. It requires explicit attributes to communicate dropdown semantics:
role="combobox"identifies the trigger element andaria-expandedcommunicates its expanded or collapsed state. The trigger element can be, for example, a read-only<input>field or a<button>.role="listbox"identifies the dropdown list expanded by the trigger.- The collapsed dropdown must be hidden from screen readers and the keyboard, for example with the
hiddenattribute ordisplay: none. role="option"identifies an option, andaria-selectedcommunicates its selection state.aria-activedescendanton the trigger tracks which option currently has focus.aria-haspopup="listbox"communicates that the trigger opens a listbox.aria-controlspoints to the element the trigger controls.