Course contentsShow
← Web Development
Lesson 930 of 2,98216. Forms and ValidationFree lesson

Select and Combobox Patterns

Implementing accessible custom dropdowns with role=combobox, aria-expanded, and proper keyboard navigation.

Select and Combobox Patterns

You'll learn how to build custom dropdown controls that work for everyone, including keyboard and screen reader users.

What Are Accessible Dropdowns?

Native <select> elements work great, but when you need custom styling or behavior (like searchable dropdowns), you'll build a custom combobox. The challenge? Making it accessible requires specific ARIA attributes and keyboard support that native elements provide for free.

Think of it like building a custom door for your house—it needs to open, close, and lock just like a standard door, even if it looks different.

The Combobox Pattern

A proper custom dropdown needs three key accessibility features:

  1. role="combobox" on the input/button that triggers the dropdown
  2. aria-expanded="true|false" to announce whether the list is open or closed
  3. aria-controls pointing to the dropdown list's ID

The list itself should have role="listbox" and each option role="option".

<div class="custom-select">
  <button 
    role="combobox" 
    aria-expanded="false" 
    aria-controls="fruit-list"
    aria-haspopup="listbox">
    Choose a fruit
  </button>
  <ul id="fruit-list" role="listbox" hidden>
    <li role="option">Apple</li>
    <li role="option">Banana</li>
    <li role="option">Orange</li>
  </ul>
</div>

Keyboard Navigation Requirements

Your custom dropdown must support:

  • Enter/Space: Open/close the list
  • Arrow keys: Navigate options
  • Escape: Close without selecting
  • Tab: Move to next form field

Update aria-expanded whenever the list opens or closes so screen readers announce the state change.

Key Takeaway: Custom dropdowns need role="combobox", aria-expanded state management, and full keyboard navigation to match native <select> accessibility—don't ship without these fundamentals.