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

feat(SelectDropdown): updated aria-live to be assertive and added aria-selected attribute to SelectDropdown #2869

Merged
merged 7 commits into from
May 2, 2024

Conversation

palak-gupta-codecademy
Copy link
Contributor

@palak-gupta-codecademy palak-gupta-codecademy commented Apr 29, 2024

Overview

As part of this PR, the aria-live attribute for SelectDropDown is made assertive. This will help screenreader in identifying changes in option selection done be user and thereby notify without any delay.

Updated aria-live to be assertive.
Adds aria-selected attribute to option focused/highlighted

PR Checklist

  • Related to designs:
  • Related to JIRA ticket: ENT-69
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

  1. Go to SelectDropdown Story
  2. Turn on VoiceOver
  3. Using TAB open select menu
  4. You should hear different option being read while changing focus on different options under select menu

Don't make me tap the sign.

PR Links and Envs

Repository PR Link PR Env
Monolith Monolith PR

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ dreamwasp
❌ palak-gupta-codecademy
You have signed the CLA already but the status is still pending? Let us recheck it.

@palak-gupta-codecademy palak-gupta-codecademy marked this pull request as ready for review April 30, 2024 13:43
Copy link
Contributor

@dreamwasp dreamwasp left a comment

Choose a reason for hiding this comment

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

have a question about changing approach to avoid direct dom manipulation, otherwise looks good + works well

Comment on lines 115 to 121
useEffect(() => {
if (inputId) {
const inputelemet = document.getElementById(inputId);
inputelemet?.setAttribute('aria-activedescendant', highlightedOption);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [highlightedOption]);
Copy link
Contributor

Choose a reason for hiding this comment

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

could you just pass the aria-activedescendant via inputProps (passing the highlightedOption as the value) to avoid direct dom manipulation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, I did tried that out but it seems react-select uses an internal component called DummyInput when search is disabled. The inputProps are not passed down to this component. Unfortunately, this makes customization of input element impossible without dom manipulation.
Here is the link for the react-select code snippet with DummyInput usage

Copy link
Contributor

Choose a reason for hiding this comment

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

normally that's the case, but i overrode that behavior with a CustomContainer that always shows an input element that receives inputProps -- it's in elements 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.

okay, yes I think this element can be updated to reflect required aria attributes. Will check this out!!

Copy link
Contributor

Choose a reason for hiding this comment

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

great, let me know if you have any questions or want to pair!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Cassie, I was able to find a fix without usage of aria-activedescendant altogether. I see that we are already setting up ariaLiveMessages for the react-select component so I have updated aria-live to be assertive. This helps screenreader in instantly recognizing and notifying any changes made as per user action.

Comment on lines 138 to 153
export const SelectDropdownOption = (props: OptionProps) => {
const { setHighlightedOption } = useContext(SelectDropdownContext);
const { isFocused, innerProps } = props;

if (isFocused) {
setHighlightedOption(innerProps.id);
}

return (
<Option
{...props}
innerProps={{ ...innerProps, 'aria-selected': isFocused }}
/>
);
};

Copy link
Contributor

Choose a reason for hiding this comment

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

love this, works great. i'm also doing some SelectDropdown a11y work so this is timed nicely

@palak-gupta-codecademy palak-gupta-codecademy changed the title feat(SelectDropdown): added aria-activedescendant and aria-selected attributes to SelectDropdown feat(SelectDropdown): updated aria-live to be assertive and added aria-selected attribute to SelectDropdown May 2, 2024
@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/[email protected]
@codecademy/[email protected]
@codecademy/[email protected]

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://6633a68a48ae561ff55b735a--gamut-preview.netlify.app

Deploy Logs

Copy link
Contributor

@dreamwasp dreamwasp left a comment

Choose a reason for hiding this comment

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

wonderful solution! thank you for improving on one of our most complicated components

@palak-gupta-codecademy palak-gupta-codecademy added the Ship It :shipit: Automerge this PR when possible label May 2, 2024
@codecademydev codecademydev merged commit 7733904 into main May 2, 2024
19 of 21 checks passed
@codecademydev codecademydev deleted the ENT-69 branch May 2, 2024 16:58
@codecademydev codecademydev removed the Ship It :shipit: Automerge this PR when possible label May 2, 2024
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.

4 participants