Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accessibility of AutocompletingTextInput component #16324

Merged
merged 3 commits into from
Mar 17, 2023

Conversation

sergiou87
Copy link
Member

Description

This PR improves accessibility of the AutocompletingTextInput with these changes:

  • Proper use of aria autocomplete-related attributes to make sure screen readers are able to focus and read through the list of suggestions.
  • Add new aria-live hidden component with the number of suggestions
  • Show the autocomplete list with nothing selected. Using the arrows keys up and down to navigate through the list will move the (screen reader) focus into the list.
  • Bonus: make the autocomplete list aware of its position on the screen and show up above the textfield if there is no enough room below it.

I have more changes from the co-author-accessibility-fixes branch that are much more specific to the Co-Authors input, so I will leave those for another PR.

Screenshots

CleanShot.2023-03-15.at.16.38.07.mp4

Release notes

Notes: [Improved] Make autocompletion suggestions more accessible for screen readers.

@tidy-dev tidy-dev self-requested a review March 15, 2023 16:53
Copy link
Member

@niik niik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @sergiou87. The one thing that feels weird to me here is that you have to hit arrow-down to autocomplete to the first match, i.e. no more typing @serg and hitting Tab to complete which is the convention that I'm most familiar with (in fact I can't think of an autocomplete that doesn't work like that). Could we make it autocomplete the top hit on Tab/Enter even if nothing is selected or would that make it fail the a11y criteria?

Something like

diff --git a/app/src/ui/autocompletion/autocompleting-text-input.tsx b/app/src/ui/autocompletion/autocompleting-text-input.tsx
index fa3f5003d..c6b5fadc9 100644
--- a/app/src/ui/autocompletion/autocompleting-text-input.tsx
+++ b/app/src/ui/autocompletion/autocompleting-text-input.tsx
@@ -520,7 +520,10 @@ export abstract class AutocompletingTextInput<
       event.key === 'Enter' ||
       (event.key === 'Tab' && !event.shiftKey)
     ) {
-      const item = currentAutoCompletionState.selectedItem
+      const item =
+        currentAutoCompletionState.selectedItem ??
+        currentAutoCompletionState.items.at(0)
+
       if (item) {
         event.preventDefault()

Also, while technically out of scope for this work I noticed how obnoxious it is hearing that first 'colon' announced on each emoji. It seems dotcom just strips the leading and trailing : when autocompleting emojis. Could we do the same?

@sergiou87
Copy link
Member Author

The one thing that feels weird to me here is that you have to hit arrow-down to autocomplete to the first match, i.e. no more typing @serg and hitting Tab to complete which is the convention that I'm most familiar with (in fact I can't think of an autocomplete that doesn't work like that). Could we make it autocomplete the top hit on Tab/Enter even if nothing is selected or would that make it fail the a11y criteria?

I share that sentiment, but as far as I understand it fails the a11y criteria because a screen reader user wouldn't know what they'd be autocompleting before hitting the tab/enter key. I also considered selecting the first item and making the screen reader read it, but then it's like moving the focus out of the input text box, which is where the screen reader user is expecting to be.

Also, while technically out of scope for this work I noticed how obnoxious it is hearing that first 'colon' announced on each emoji. It seems dotcom just strips the leading and trailing : when autocompleting emojis. Could we do the same?

Sounds good!

@sergiou87
Copy link
Member Author

@niik I've improved readability of the emoji autocomplete list as you suggested, and I also improved readability of the issue autocompletion elements by adding a space between the issue number and the title (before this, the screen reader would read both the number and the first word of the title as if they were one).

I also used the secondary text color for the issue number, which is what dotcom seems to do too.

@sergiou87 sergiou87 requested a review from niik March 16, 2023 09:53
Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Thank you for all your work on this.

@sergiou87 sergiou87 merged commit d9f42e8 into development Mar 17, 2023
@sergiou87 sergiou87 deleted the autocompleting-input-a11y branch March 17, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants