Building an Accessible Combobox
What you'll learn: How to create a combobox widget with proper ARIA roles, keyboard navigation, and focus management for screen reader and keyboard users.
What Is a Combobox?
A combobox combines a text input with a popup list of suggestions—think of a search box that shows matching results as you type. It's like having a GPS that suggests addresses as you enter your destination: you can either type the full address yourself or pick from the suggestions.
Core Implementation Requirements
HTML Structure
Start with a text <input> wrapped in a container. The input needs role="combobox", aria-expanded to indicate popup state, and aria-controls pointing to the listbox ID:
<div>
<input type="text"
role="combobox"
aria-expanded="false"
aria-controls="suggestions"
aria-autocomplete="list">
<ul id="suggestions" role="listbox" hidden>
<li role="option">Option 1</li>
<li role="option">Option 2</li>
</ul>
</div>
Keyboard Navigation
You must handle:
- Down Arrow: Open popup and move focus through options
- Up Arrow: Navigate backward through options
- Enter: Select the focused option
- Escape: Close popup and clear selection
Focus Management
Keep keyboard focus on the input while visually highlighting options using aria-activedescendant. Update this attribute to point to the currently highlighted option's ID—this tells screen readers which option is active without moving actual focus.
When an option is selected, update the input's value and announce the selection by temporarily updating aria-live regions or the input itself.
Key Takeaway: An accessible combobox requires coordinated ARIA roles (combobox, listbox, option), keyboard handling (arrows, Enter, Escape), and focus management using aria-activedescendant to bridge visual highlighting with screen reader feedback.