Skip to content

Conversation

@kyledurand
Copy link
Member

@kyledurand kyledurand commented Nov 27, 2020

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 mountWithApp and added aria tests
Added 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

  • Tested on mobile
  • Tested on multiple browsers
  • Tested for accessibility
  • Updated the component's README.md with documentation changes
  • Tophatted documentation changes in the style guide
  • For visual design changes, pinged one of @ HYPD, @ mirualves, @ sarahill, or @ ry5n to update the Polaris UI kit

@kyledurand kyledurand force-pushed the navigation_render-sub-sections-with-aria-attributes branch from 7501eb7 to 049a50c Compare November 27, 2020 19:37
@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2020

🟢 This pull request modifies 7 files and might impact 3 other files.

Details:
All files potentially affected (total: 3)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

🧩 playground/DetailsPage.tsx (total: 0)

Files potentially affected (total: 0)

🎨 src/components/Navigation/Navigation.scss (total: 1)

Files potentially affected (total: 1)

🧩 src/components/Navigation/components/Item/Item.tsx (total: 2)

Files potentially affected (total: 2)

🧩 src/components/Navigation/components/Item/components/Secondary/Secondary.tsx (total: 3)

Files potentially affected (total: 3)

🧩 src/components/Navigation/components/Item/components/Secondary/tests/Secondary.test.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Navigation/components/Item/tests/Item.test.tsx (total: 0)

Files potentially affected (total: 0)


let secondaryNavigationMarkup: ReactNode = null;

if (subNavigationItems.length > 0 && showExpanded) {
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

@AndrewMusgrave AndrewMusgrave left a 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'}}
Copy link
Member

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 🤔

Copy link
Member Author

@kyledurand kyledurand Jan 11, 2021

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);
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Member

@BPScott BPScott left a 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 :shipit:

@kyledurand kyledurand force-pushed the navigation_render-sub-sections-with-aria-attributes branch from 049a50c to 2d3d2da Compare January 11, 2021 20:29
@kyledurand kyledurand force-pushed the navigation_render-sub-sections-with-aria-attributes branch from 2d3d2da to 13ea6d8 Compare January 11, 2021 20:29
@kyledurand kyledurand merged commit 196e116 into master Jan 11, 2021
@kyledurand kyledurand deleted the navigation_render-sub-sections-with-aria-attributes branch January 11, 2021 20:49
sylvhama pushed a commit that referenced this pull request Mar 26, 2021
* [Navigation] Render sub-sections with aria attributes

* Switch tests to use mountWithApp

* Add test for Secondary
@st-baonguyen
Copy link

st-baonguyen commented Sep 30, 2022

@kyledurand @AndrewMusgrave
Excuse me! I have a case about expanded navigation.
I have 2 item in subNavigation, and i want to expanded subNavigation when I click main menu and subNavigation, I tried by use expanded and onToggleExpandedState property but it is not expanded, When I click subNavigation, subMenu is unexpanded and it just expanded when selected of main menu = true. But I don't want use selected property. Pls help me. Thank you so much

@kyledurand
Copy link
Member Author

@st-baonguyen can you create a playground or file an issue with more context?

@st-baonguyen
Copy link

st-baonguyen commented Oct 5, 2022

@kyledurand Sorry about this delay.
I cann't share my source but I had create a playground on Codesanbox. Pls check it. Thank you
Could you check at line 40.
Expended = true, subNavigation doesn't expended, but with selected = true, subNavigation expended.
And I don't know what is Expended used for?.
https://codesandbox.io/s/navigation-sandbox-forked-svqgdn?file=/Nav.js

@kyledurand
Copy link
Member Author

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 expanded is no longer needed. We'd have to check every implementation and prop combination used internally to be sure and we don't have the bandwidth for that right now.

Another way to achieve the expanded state is to set matches: true, or matchPaths: ['<path1>', <path2>].

This will also give you the selected style, however, which is what we want for our use case.

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