mdn / yari

The platform code behind MDN Web Docs
Mozilla Public License 2.0
1.19k stars 503 forks source link

MDN autocomplete accessibility: aria-live region doesn't update consistently, unexpected context change, focus handling on Esc #4407

Open patrickhlauke opened 3 years ago

patrickhlauke commented 3 years ago

Posted these as a comment on the https://hacks.mozilla.org/2021/08/mdns-autocomplete-search blog post, but perhaps more productive doing it here...

Screen reader behaviour could be improved a tad. The a11y-status-message container is not always updated correctly – try typing in “test” letter by letter; on the first letter, it announces that 10 results are available; any subsequent letters that are typed in (and change the number of results) don’t update the message container/make any announcement. Other words are fine though … e.g. “axes” announces the different numbers of results as you go along. It’s a bit flakey.

Also, for keyboard users in general, once one of the suggestions is highlighted (after reaching it with cursor keys), but the user decides to bail out by using “Tab”, the result is triggered anyway as if they had pressed enter. It should just close the autocomplete results and move focus along.

Pressing Esc to close the autocomplete popup leads to focus being lost. While browsers generally error correct for this, it’s not reliable. Focus should be explicitly moved to the search input again.

peterbe commented 3 years ago

Love it! Thanks for taking the time.

I actually don't know what the "a11y-status-message container" is. How do I see this?

Pressing Tab when you've hovered over a search result really shouldn't be interpreted as a click on that search result. You're right. Definitely a bug. I don't see us doing anything specific in our code with Tab. Perhaps it's a bug in Downshift (useCombobox) or how we use it. Hmm...

Regarding Esc causing a full blur trigger is our fault. I created: https://github.com/mdn/yari/pull/4416

patrickhlauke commented 3 years ago

I actually don't know what the "a11y-status-message container" is. How do I see this?

it's injected dynamically into the page the first time you hover over or focus the combobox

open autocomplete and the developer tools, with the a11y-status-message element highlighted just before the closing body tag

messages that get announced by screen readers are dynamically added, and then removed, here (if you keep an eye on the element in devtools, you'll see it updates briefly after each keystroke - in the case of "axis" - or not - in the case of "test"). there must be something borked in the logic that decides when to send messages.

patrickhlauke commented 3 years ago

Pressing Esc to close the autocomplete popup leads to focus being lost. While browsers generally error correct for this, it’s not reliable. Focus should be explicitly moved to the search input again.

belatedly, an additional consideration: Esc also clears whatever the user had entered so far in the search box. This is unexpected/frustrating (a user may just want to type a search term in, hits Esc to move the autocomplete out of the way, but wants to carry on typing out the search term to do a traditional search). Suggest the value of the search box input should not be blanked/emptied when the user hits Esc (though this may cause additional considerations - should the box reappear if the user carries on typing? or should it now remain closed until next time the user sets focus back into the input, and optionally re-open it explicitly if the user does something like pressing cursor down? the latter sounds like the most robust)

peterbe commented 3 years ago

an additional consideration: Esc also clears whatever the user had entered so far in the search box.

I can not reproduce that.

https://user-images.githubusercontent.com/26739/129629190-85ca598d-8647-4fd7-b4f7-2b5d3c745790.mov

patrickhlauke commented 3 years ago

Interesting. It doesn't clear it in Firefox, but it does in Chrome and Edge.

animated gif showing the dropdown in Chrome - typing 'tes' then pressing 'Esc' closes the dropdown and clears the text entry

peterbe commented 3 years ago

Confirmed! ...in Chrome :(

caugner commented 1 year ago

Esc also clears whatever the user had entered so far in the search box.

FWIW Esc now clears both in Chrome and Firefox.

caugner commented 1 year ago

Hi @patrickhlauke, would you mind checking for us if this is still an issue? Thank you! 🙏

patrickhlauke commented 1 year ago

tested briefly now with latest Chrome and NVDA:

These parts seem to work properly now.

However, these aspects are still not quite right:

caugner commented 1 year ago

Thank you for your quick response @patrickhlauke, much appreciated! 🙌