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.
li.classList.toggle('active', i === active) 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
A travel site's booking form has a Destination field. Type "por" and a list drops down under it: Porto, Portland, Portsmouth, with a line above it saying "3 suggestions". With a mouse, a click on Portland fills the field. With a keyboard, it depends on the build. In one version the arrow keys do nothing, and Tab leaves the field for the Search button, so the list can't be used at all. In another, the down arrow moves a blue highlight through the cities and Enter picks one, but a screen reader says nothing as it moves, or only reads back "por". In both versions the "3 suggestions" line is never read, so nothing tells a screen reader user that a list opened. Type "pxq" and the line changes to "No destinations found", and that is silent too.
Success Criterion 2.1.1 asks that everything a mouse can do can be done with a keyboard. In the first version, the suggestions are li elements with a click handler: they can't take focus and no key reaches them. Success Criterion 4.1.2 asks that a control's role and state, and anything the user can change, are available to assistive technology. In the second version, the field is still announced as a plain text field, the list has no role, and the highlight is a CSS class: the keyboard works, but the browser has nothing to tell a screen reader about which suggestion is highlighted or that a list is open. The line above the list fails a third criterion. "3 suggestions" and "No destinations found" are status messages: they report the result of what the person typed without moving focus, and Success Criterion 4.1.3 asks that they are announced. The line is a plain p. A screen reader is reading the field the person types in, and a browser doesn't announce text that changes somewhere else unless that element is a status or live region, so the words appear on screen and are never said.
Type-ahead fields often lead into the most important step of a form, such as a destination, an address or a product. On a phone, the list can open under the on-screen keyboard, so even sighted users may depend on the count line to know there is anything to pick.
4 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (affected)
- Seizures (not affected)
- Limited manipulation Keyboard and switch users can't reach the suggestions, so they have to type the whole name exactly, and a spelling slip gives no match.
- Without vision Screen reader users aren't told that suggestions appeared or which one is highlighted, and don't hear when nothing matched, so they may send a half-typed word.
- Limited vision People with low vision who find the pointer hard to track can't pick a suggestion from the keyboard instead, and magnifier users zoomed in on the field may not see the list open below it.
- Limited language, cognitive and learning abilities People who rely on suggestions to spell a place or product name lose that help when they can't pick from the list.
A scan loads the page and finds a labelled text field. The list doesn't exist until someone types, so there is nothing for it to check, and a list that does exist is markup with no ARIA to be wrong. AI assistants asked for an autocomplete often write exactly the second version: keydown handlers and an active class, sometimes with role="listbox" added to the list but no aria-activedescendant on the field, which still leaves the highlight silent. Others move focus into the list on the down arrow, so typing another letter goes nowhere. Only typing, arrowing and listening shows whether the list works.
What the checkers report
- axe DevTools
- Required ARIA attributes must be provided
- Lighthouse
[role]s do not have all required[aria-*]attributes
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?
The fix
Let the arrow keys reach the suggestions, and announce them
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.
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
- Give the field
role="combobox",aria-autocomplete="list",aria-expandedandaria-controls, and the listrole="listbox"and a name. The field is announced as a combo box that says whether its list is open. - Render each suggestion as an
optionwith anid, and keeparia-expandedin step asshow()opens and closes the list. - Keep focus in the field, so typing another letter still works, and have the arrow keys move
aria-activedescendantto the highlighted option, so each arrow press reads that city out. - Fill the field on Enter or a click, and close the list on Escape or when the field loses focus. The list's
mousedownhandler keeps focus in the field, so a click picks before the list closes. - 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.
- 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, soaria-expandedand the highlight are reset with them, and keep the count waiting for the pause in typing.
Why this fix: Style from the state, not a class
Both pass 2.1.1 and 4.1.2. The combobox also passes 4.1.3, with its count line as a status region; the datalist shows no count, so it has no status message to announce. Use the ARIA combobox: it behaves the same in every browser, its list zooms and can be drawn for forced colors, it can show and announce a count, and the datalist's gaps are in the browser, where no code of yours can close them. The cost is the script above, which is yours to test and maintain. A datalist is a reasonable shortcut for a plain list of words on an internal tool whose browsers and screen readers you know, where the gaps above don't reach anyone who uses it.
If the list is short and the answer must be one of its entries, such as a country, a native select may serve better than any combobox. An autocomplete suits a long list, or one where people may type something that isn't on it.
Don't move DOM focus into the list. With focus on an option, the next letter typed goes nowhere, and screen readers leave their editing mode. Keep focus in the field and move aria-activedescendant. Don't put aria-live on the list either: every city would be read on each keystroke. The list's mousedown handler only keeps focus in the field; the option is chosen on click, so a press that slides off chooses nothing, as buttons that act on press and can't be cancelled explains.
People typing Japanese, Chinese or Korean press Enter to confirm a conversion and the arrow keys to choose between its candidates, and the handler above sees those keys too. Return from it first while event.isComposing is true or event.keyCode is 229, so the confirming Enter doesn't pick the highlighted city.
The count line must be in the page before the first keystroke, and outside anything your framework re-renders with the list, or its first change is not announced. Some screen readers read nothing when the same words are written twice; if "3 suggestions" can follow "3 suggestions", clear the line before writing it again.
Some combobox components in UI libraries implement this pattern, and some ship the second Before with an accessible name. Check any library by typing, arrowing and listening, as in the steps below, before you trust its documentation. For other dropdown failures, see search panels that close on Tab and drop keyboard focus and search and filter results that update without a word. When people pick from a fixed list without typing, see custom dropdowns that keyboards and screen readers can't use.
Verify the fix
5 checks, no mouse.
Test with: Keyboard, Screen reader, Zoom, Forced colors
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.
References
- ARIA APG: combobox (opens in a new tab)
- ARIA APG: combobox-autocomplete-list (opens in a new tab)
- WCAG Understanding: keyboard (opens in a new tab)
- WCAG Understanding: name-role-value (opens in a new tab)
- WCAG Understanding: status-messages (opens in a new tab)
- developer.mozilla.org: combobox_role (opens in a new tab)
- developer.mozilla.org: datalist (opens in a new tab)
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.