-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Navigation] Add aria attributes for sub nav items #3661
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
[Navigation] Add aria attributes for sub nav items #3661
Conversation
7501eb7 to
049a50c
Compare
|
🟢 This pull request modifies 7 files and might impact 3 other files. Details:All files potentially affected (total: 3)📄
|
|
|
||
| let secondaryNavigationMarkup: ReactNode = null; | ||
|
|
||
| if (subNavigationItems.length > 0 && showExpanded) { |
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 is the scariest thing for me in this PR. This makes sub menus and their items render in the DOM, though hidden. I did this so that the aria-controls id will have a valid reference ID but not sure that's super necessary to see until the sub menu has actually rendered.
This broke the Nav in web the last time I tried this, for adding animations but Alex's fixes to Collapsible has fixed that.
Anyone see any potential issues in doing this?
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 makes sub menus and their items render in the DOM, though hidden. I did this so that the aria-controls id will have a valid reference ID but not sure that's super necessary to see until the sub menu has actually rendered.
Hmm, interesting! I'm not sure about aria-control, but certain screen readers require elements to always be in the DOM for certain attributes (e.g aria-live)
Anyone sees any potential issues in doing this?
As long as the Collapsible changes roll out ok and collapsible hides the children from keyboard access I don't foresee any isssues.
AndrewMusgrave
left a comment
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.
🎩 LTGM ✅
| <Collapsible | ||
| id={id || uid} | ||
| open={expanded} | ||
| transition={{duration: '0ms', timingFunction: 'linear'}} |
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.
TIL we use collapsible in navigation - why do we need these props now? I don't recall there being an animation before 🤔
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.
Collapsible defaults to an animation so I'm cancelling that here with 0ms.
| overflow-x: var(--p-override-visible, hidden); | ||
|
|
||
| &.isExpanded { | ||
| margin-bottom: spacing(tight); |
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.
Nice!
|
|
||
| let secondaryNavigationMarkup: ReactNode = null; | ||
|
|
||
| if (subNavigationItems.length > 0 && showExpanded) { |
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 makes sub menus and their items render in the DOM, though hidden. I did this so that the aria-controls id will have a valid reference ID but not sure that's super necessary to see until the sub menu has actually rendered.
Hmm, interesting! I'm not sure about aria-control, but certain screen readers require elements to always be in the DOM for certain attributes (e.g aria-live)
Anyone sees any potential issues in doing this?
As long as the Collapsible changes roll out ok and collapsible hides the children from keyboard access I don't foresee any isssues.
BPScott
left a comment
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 was a little scared by the size of this PR but then I looked and found out most of it was migrating tests to use @shopify/react-testing!
I've not got much context on this but it looks like it does what you say it should ![]()
049a50c to
2d3d2da
Compare
2d3d2da to
13ea6d8
Compare
* [Navigation] Render sub-sections with aria attributes * Switch tests to use mountWithApp * Add test for Secondary
|
@kyledurand @AndrewMusgrave |
|
@st-baonguyen can you create a playground or file an issue with more context? |
|
@kyledurand Sorry about this delay. |
|
I see what you mean @st-baonguyen, thanks for the playground. The Nav was ported over from the original rails implementation in ~2017, and we needed to copy the functionality from there. We might have changed the way the nav works along the way and Another way to achieve the expanded state is to set This will also give you the selected style, however, which is what we want for our use case. |
WHY are these changes introduced?
Fixes https://github.com/Shopify/polaris-ux/issues/448
WHAT is this pull request doing?
Always render sub nav items so that aria-controls has an id to reference
Adds aria-expanded true/false when nav items have sub items
Add area-controls attribute with ID and corresponding id to Collapsible
Converted Navigation Item tests to use
mountWithAppand added aria testsAdded missing tests for Secondary
How to 🎩
Check out the details page or any navigation examples and make sure that only nav items with sub navs have the two attributes mentioned above. Make sure that aria-expanded is true when the sub nav menu is expanded, and false when it isn't
🎩 checklist
README.mdwith documentation changes