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

Add autocomplete screen reader support #48

Merged
merged 19 commits into from
Oct 29, 2021
Merged

Conversation

nmanu1
Copy link
Contributor

@nmanu1 nmanu1 commented Oct 27, 2021

Add a ScreenReader component that is used to provide screen reader instructions and announcements. Use this component in InputDropdown to give autocomplete instructions and screen reader announcements for number of autocomplete options found.

J=SLAP-1402
TEST=manual

Check that screen reader instructions and announcements are correct in the sample app. An announcement is made for each input change and on clicking the input bar if there is input present.

@coveralls
Copy link

coveralls commented Oct 27, 2021

Coverage Status

Coverage remained the same at 75.269% when pulling 20a0ae9 on dev/autocomplete-screen-reader into 37050f2 on main.

sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
@nmanu1 nmanu1 requested review from oshi97 and yen-tt October 27, 2021 19:41
@nmanu1 nmanu1 requested a review from yen-tt October 27, 2021 23:21
@@ -22,3 +22,18 @@
.result-description {
padding-left: 2em;
}

.sr-only {
position: absolute;
Copy link
Member

Choose a reason for hiding this comment

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

What's the reasoning behind position: absolute here? Setting that can make managing the DOM more difficult because it pulls the element out of the normal flow of the document, and I want to make sure it's use is necessary here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got this from the sr-only styling in the SDK. Wouldn't we want screen-reader only elements to be outside the normal flow?

Copy link
Member

Choose a reason for hiding this comment

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

Ya, that makes sense to me assuming the element is hidden some way. It looks like clip: rect(0,0,0,0) may be doing the hiding. I'm wondering if display: none would work instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

display: none hides something from the screen reader as well as visually, so it shouldn't be used here

Copy link
Member

Choose a reason for hiding this comment

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

Got it. There's also visibility: hidden which doesn't remove the element from the layout which might work and be a little clearer than clip

Copy link
Contributor Author

Choose a reason for hiding this comment

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

visibility: hidden also hides it from screen readers, just like display: none


const prevAutcompleteCountText = autocompleteCountRef.current.innerHTML;

if (shouldDisplayDropdown) {
Copy link
Contributor

@oshi97 oshi97 Oct 28, 2021

Choose a reason for hiding this comment

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

should this go in a useEffect? generally speaking there shouldn't be side effects in a render function, since the function itself may be called multiple times, and I believe multiple renders can be batched into a single DOM update. I think that right now, if the component rerenders for some reason that isn't the user typing in different text, that the screen reader will do a fresh read even though the input text has not changed? This might be an impossible scenario right now but is just an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was preventing duplicate announcements with the check in updateAutcompleteCountText that only sets the innerHTML if the number of options changes. so, I believe the only time the screen reader would announce something is if the number of options changes or if the user input changes. but, if it is still better to put it in a useEffect, then I can try moving lines 84-90 into the useEffect that is a little later in the code

@nmanu1 nmanu1 requested review from oshi97 and cea2aj October 28, 2021 22:10
sample-app/src/components/SearchBar.tsx Outdated Show resolved Hide resolved
sample-app/src/components/SearchBar.tsx Outdated Show resolved Hide resolved
sample-app/src/components/SearchBar.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
@oshi97
Copy link
Contributor

oshi97 commented Oct 28, 2021

This is already looking good! think we just need to iron out the ScreenReader interface

@nmanu1 nmanu1 requested a review from oshi97 October 28, 2021 23:52
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/ScreenReader.tsx Outdated Show resolved Hide resolved
sample-app/src/components/InputDropdown.tsx Outdated Show resolved Hide resolved
@nmanu1 nmanu1 requested a review from oshi97 October 29, 2021 18:41
Copy link
Contributor

@oshi97 oshi97 left a comment

Choose a reason for hiding this comment

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

looks great!

Copy link
Member

@cea2aj cea2aj left a comment

Choose a reason for hiding this comment

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

🔥

@nmanu1 nmanu1 merged commit 9c5c492 into main Oct 29, 2021
@nmanu1 nmanu1 deleted the dev/autocomplete-screen-reader branch November 30, 2021 00:26
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.

None yet

5 participants