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
Storybook dropdown should be accessible 11724 #12295
Storybook dropdown should be accessible 11724 #12295
Conversation
@@ -67,6 +67,7 @@ const themeSwitcherDecorator = (storyFn) => { | |||
}; | |||
|
|||
addDecorator(themeSwitcherDecorator); | |||
addDecorator((Story) => <Story />); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows us to use Preact hooks in Storybook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works beautifully!! :)
-- When using a screen reader (I have tested this on Safari with VoiceOver), the expanded/collapsed state of the dropdown should be announced when the activator button is focused
Also, super impressed that you added screen reader QA instructions to this -- I love that! Thank you 💞
### Dropdown accessibility | ||
|
||
When a dropdown of options is opened, focus should be sent to the first | ||
interactive item inside the dropdown content. When the dropdown is closed, focus | ||
should return to the activator button. If there are no interactive items, | ||
consider using an `aria-live` region to ensure the new content is announced to | ||
screen-reader users when the dropdown appears. | ||
|
||
A user should be able to open and close the dropdown by keyboard (e.g. using | ||
Enter and Escape), and appropriate `aria` (e.g. `aria-haspopup`) should be used | ||
to indicate the relationship between the activator button and the dropdown | ||
content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏽👏🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aitchiss, love the idea!
I tried to test it and I wasn't able to use the keyboard, I'm 100% sure I'm doing something wrong though.
- I checked out the PR
- Ran
yarn storybook
- Went to http://localhost:6006/?path=/story/components-dropdowns--default
- Tabbed a bit until the dropdown was in focus but as I hit the enter key, the page reloads (I tried both on Firefox and Chromium-based Edge)
Here's a gif if it can help:
@@ -9,3 +9,16 @@ dependent on width: | |||
- < 250px: 16px 251 - 320px: 24px | |||
|
|||
FYI: Dropdowns use “Box” component as background, with Level 3 elevation. | |||
|
|||
### Dropdown accessibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Hey @rhymes - thanks for the review! This is strange as the gif you've posted doesn't include my changes! In the new version the button should read "click to trigger dropdown" 🤔 I'm not sure if maybe some weird caching has gotten you and maybe you could try re-running? Either way, I've noticed there's a lack of visible focus style on the link I've added to the dropdown which I think could be potentially confusing too, so I'm going to take a look at that this morning |
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
@aitchiss I managed to see your code, I had to remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried again with Edge, Chrome and Firefox and it works, thank you!
thanks @rhymes - good to know about that |
@vaidehijoshi / @rhymes - I've pushed a commit since you approved - it's a minor CSS change to make the focus on the dropdown's link visible. Just in case you want to have a look at it. |
@aitchiss re-tested, can't accept twice, but let's say: signed and sealed :D |
What type of PR is this? (check all applicable)
Description
This PR updates the Dropdown Storybook stories so that they are keyboard accessible. The dropdowns can now be opened and closed by keyboard (Enter / Esc), and can also be closed by clicking outside of the dropdown.
Notes have been added to the stories to give context on accessibility implications when using the dropdown component.
This PR ensures that our Storybook documents accessible usage of the Dropdown component, however wider work is needed to ensure all dropdowns used throughout the app are consistently handling keyboard events and focus in a way optimised for accessibility. This will need to be a generalised approach that accounts for both Preact and non-Preact usage. A new issue has been created for this here: #12297
Related Tickets & Documents
Closes #11724 - Storybook dropdown should be accessible
QA Instructions, Screenshots, Recordings
-- Focus the activator button by pressing the Tab key
-- When pressing enter on the focused button, the dropdown content should appear, and focus should be sent to the link inside the content
-- When the dropdown is open, pressing Escape should close it
-- When the dropdown is open, clicking outside of the dropdown content should close it
-- Clicking the button with the mouse should toggle the dropdown content open/closed
-- When using a screen reader (I have tested this on Safari with VoiceOver), the expanded/collapsed state of the dropdown should be announced when the activator button is focused
UI accessibility concerns?
See above QA instructions.
Please also note I've disabled a jsx-a11y warning regarding the
keyUp
handler on the wrappingdiv
in bothDropdown.stories.jsx
anddropdown.html.stories.jsx
. The event handler has been added to the containing (non-interactive)div
to ensure Escape key presses are captured to collapse the dropdown content. As the containingdiv
isn't expected to be interactive, the linter warning is in this case a false positive. A comment has been added to the code to this effect too.Added tests?
Added to documentation?
Admin Guide
[optional] Are there any post deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?