Skip to content
easeweb
Search topics

Autocomplete fields with silent, mouse-only suggestions

A type-ahead field's suggestions are a plain list with click handlers or a CSS highlight, so a keyboard can't pick one and screen readers never hear them.

WCAG 2.2
SC 2.1.1ASC 4.1.2ASC 4.1.3AA· new in 2.1
Required by
Section 508 · EN 301 549 (EU)
Broken li.classList.toggle('active', i === active)
The accessibility problem illustrated: No vision:Which place is picked?
01

The problem

Keyboard users can't pick a suggestion, and screen reader users can't tell that suggestions appeared, which one is highlighted, or that nothing matched

02

Try it

Pick Portland in Destination without the mouse

  • Broken 1: type por in Destination, press the down arrow, then Enter. Can you pick Portland? The panel shows what a screen reader says as you type and move. Is the count under the field read out? Try pxq too, which matches nothing.

  • Broken 2: the down arrow now moves a highlight. Does the panel ever say which city is highlighted, or that you picked one?

  • Apply a fix. Pick Portland the same way: what is said as you move through the list and pick? Try pxq again too.

Broken Can you fix this?

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let the arrow keys reach the suggestions, and announce them

Before

Suggestions that only a click can pick

<label for="dest">Destination</label><input id="dest" type="text" autocomplete="off"><p id="dest-count"></p><ul id="dest-list" class="suggestions" hidden></ul>
What is wrong4 points
  • The keyboard can't reach the suggestions: they are list items with a click handler, so they can't take focus.
  • A city can be picked only with a click: no key reaches the list.
  • Screen reader users aren't told that suggestions appeared: neither the field nor the list has a role or state that says a list is open.
  • Screen reader users never hear "3 suggestions": the count line is a plain p, so the words only appear on screen.
After

An ARIA combobox

<label for="dest">Destination</label><input id="dest" type="text" role="combobox" autocomplete="off"  aria-autocomplete="list" aria-expanded="false" aria-controls="dest-list"><p id="dest-count" role="status"></p><ul id="dest-list" role="listbox" aria-label="Destinations" hidden></ul>
How it is fixed6 steps
  1. Give the field role="combobox", aria-autocomplete="list", aria-expanded and aria-controls, and the list role="listbox" and a name. The field is announced as a combo box that says whether its list is open.
  2. Render each suggestion as an option with an id, and keep aria-expanded in step as show() opens and closes the list.
  3. Keep focus in the field, so typing another letter still works, and have the arrow keys move aria-activedescendant to the highlighted option, so each arrow press reads that city out.
  4. Fill the field on Enter or a click, and close the list on Escape or when the field loses focus. The list's mousedown handler keeps focus in the field, so a click picks before the list closes.
  5. Make the count line a status region that is in the page from the start, and fill it once typing pauses, so "3 suggestions" and "No destinations found" are announced once.
  6. Draw the highlight from aria-selected, with a transparent outline that turns into a real one in forced colors, where the background fill is dropped.

This fixes both Befores and passes 2.1.1, 4.1.2 and 4.1.3.

Matched letters in bold, a second line such as the country, or results from a server are often why a team keeps its own list. Each can be added, as long as it leaves those steps intact.

  • Matched letters in bold: wrap them inside the option, so the option's text, which is read out and fills the field, is still the city's name.
  • A second line, such as the country: keep it inside the option, so it is read with the city, and fill the field with the city alone.
  • Results from a server: pass them through show() as they arrive, so aria-expanded and the highlight are reset with them, and keep the count waiting for the pause in typing.

Easily confused
04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Zoom, Forced colors

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared field or autocomplete component changes.

How screen readers handle role="status" and aria-expanded

Limits

This is a starting pattern for a list autocomplete, not for comboboxes that complete text inline, open a grid or a tree, or allow several choices. The snippets leave out fetching and matching. When each chosen suggestion becomes a chip, see tag chips whose × the keyboard never reaches for the chips and their remove buttons. Test the complete journey, with your real data, in the browsers and assistive technology you support.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service