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(chrome)!: improves markup structure for Nav items #1784

Merged
merged 9 commits into from
Apr 10, 2024

Conversation

geotrev
Copy link
Contributor

@geotrev geotrev commented Apr 9, 2024

Description

Introduces Nav.List subcomponent for a semantically accurate navigation list.

Detail

  • introduced Nav.List as a wrapper for Nav.Item
  • React Context is used to detect if Nav.Item is within a Nav.List, and if so, includes a styled li
  • Requires consumers to keep logo/brandmark items out of Nav.List

New composition API:

<Chrome>
  <Nav> // <nav>
    <Nav.Item hasLogo /> // div
    <Nav.List> // <ul>
      <Nav.Item /> // <li>
      <Nav.Item />
      <Nav.Item />
    </Nav.List>
    <Nav.Item hasBrandmark /> // div
  </Nav>
</Chrome>

Checklist

  • πŸ‘Œ design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • 🀘 renders as expected with Bedrock CSS (?bedrock)
  • πŸ’‚β€β™‚οΈ includes new unit tests. Maintain existing coverage (always >= 96%)
  • β™Ώ tested for WCAG 2.1 AA accessibility compliance
  • πŸ“ tested in Chrome, Firefox, Safari, and Edge

@coveralls
Copy link

coveralls commented Apr 9, 2024

Coverage Status

coverage: 96.09% (-0.1%) from 96.234%
when pulling 8896a4d on george/chrome-navitems
into 9f3aa37 on next.

@geotrev geotrev changed the title 🚧 feat(chrome): accessibility improvements for Nav items feat(chrome): accessibility improvements for Nav.Items Apr 9, 2024
@geotrev geotrev changed the title feat(chrome): accessibility improvements for Nav.Items feat(chrome): improves markup structure for Nav items Apr 9, 2024
@geotrev geotrev marked this pull request as ready for review April 9, 2024 18:54
@geotrev geotrev requested a review from a team as a code owner April 9, 2024 18:54
display: flex;
flex: 1;
flex-direction: column;
order: -1;
Copy link
Contributor

@ze-flo ze-flo Apr 9, 2024

Choose a reason for hiding this comment

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

CSS order rules can lead to accessibility problems and I've had mixed experiences with them. Do we still need these rules or should we leave it to the user to specify the correct order (potential breaking change πŸ’₯)?

https://developer.mozilla.org/en-US/docs/Web/CSS/order#accessibility_concerns
https://www.w3.org/TR/css-flexbox-1/#order-accessibility

Copy link
Contributor Author

@geotrev geotrev Apr 9, 2024

Choose a reason for hiding this comment

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

Actually, you just jogged my senses a bit. Since this element is just a ul and it's a container, it shouldn't land in an unexpected render order. So, we can probably just remove these I think? πŸ€”

I'll give it a quick test to confirm, and we can discuss inconsistencies if there are any!

Copy link
Contributor Author

@geotrev geotrev Apr 9, 2024

Choose a reason for hiding this comment

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

I think I see why order is used here.

It's to ensure that a child composition of:

<Nav>
  <Nav.List>
    <Nav.Item hasBrandmark />
    <Nav.Item>
      <Nav.ItemText />
      <Nav.ItemIcon />
    </Nav.Item>
    <Nav.Item hasLogo />
  </Nav.List>
</Nav>

Renders in the expected way in the DOM:

<nav>
  <ul>
    <li class="StyledLogoItem /> <!-- logo first -->
    <li class="StyledItem">
      <span class="StyledItemIcon" /> <!-- icon first -->
      <span class="StyledItemText" />
    </li>
    <li class="StyledBrandmarkItem" /> <!-- brandmark last -->
  </ul>
</nav>

E.g., a break-prevention measure. I can't speak to if this is still desirable though. I assume so but maybe JZ or design have further insights. I would agree it is a bit heavy-handed but I can understand the logic after toying with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And now I see that removing order: -1 from <Nav> also changes the above ^ behavior in this PR vs. main/next, which I'll revert.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for your excellent explanation. πŸ’― It looks like removing order isn't so trivial after all and definitely falls out of scope for this PR. Perhaps something we can revisit in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree on revisiting if it makes sense!

Copy link
Member

Choose a reason for hiding this comment

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

The order CSS throughout Chrome is intentional, and despite the a11y concerns we keep it because enforcing consistent UX tab ordering despite consumer usage is the more important concern. Perhaps if/when a grid layout vs. flex is explored in the future, we can reevaluate.

Copy link
Contributor

@ze-flo ze-flo left a comment

Choose a reason for hiding this comment

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

LGTM πŸ”₯ πŸš€

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

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

In accordance with the a11y issue we're attempting to address, we're looking for logo and brandmark items to live outside the list. Expecting to see:

<Nav>
  <Nav.Item hasLogo />
  <Nav.List>
    <Nav.Item ... />
    <Nav.Item ... />
    <Nav.Item ... />
  </Nav.List>
  <Nav.Item hasBrandmark />
</Nav>

This means <Nav.Item> will need context to understand whether to render a <li> or not.

@geotrev geotrev requested a review from jzempel April 10, 2024 16:57
@geotrev
Copy link
Contributor Author

geotrev commented Apr 10, 2024

Thanks @jzempel - that detail wasn't immediately clear to me from our previous conversations. I recall you mentioned context but I didn't connect that to the logo/brandmark items being excluded from the list. Should be updated now.

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

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

Approved, with minor URL comment for consideration.

@@ -76,6 +76,9 @@ consider additional positioning prop support on a case-by-case basis.
- `CollapsibleSubNavItem` -> `SubNav.CollapsibleItem`
- `SubNavItem` -> `SubNav.Item`
- `SubNavItemText` -> `SubNav.ItemText`
- Added `Nav.List` as a semantic wrapper for `Nav.Item`. See
[README](https://github.com/zendeskgarden/react-components/blob/main/packages/chrome/README.md#usages)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a relative path so that it is valid whether on next or main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I wasn't sure if that was possible here. Good call. I'll update and test it before I merge!

@ze-flo
Copy link
Contributor

ze-flo commented Apr 10, 2024

For consistency, it might be good to use the dot notation in this story:

<HeaderItem aria-label="Products">
<HeaderItemIcon>
<Icon />
</HeaderItemIcon>
</HeaderItem>
<HeaderItem isRound aria-label="User profile">
<Avatar {...args} size="extrasmall">
<img alt="Example User" src="images/avatars/chrome.png" />
</Avatar>
</HeaderItem>
</Header>

@geotrev
Copy link
Contributor Author

geotrev commented Apr 10, 2024

Dang @ze-flo amazing snipe on that pattern file! haha

@geotrev geotrev changed the title feat(chrome): improves markup structure for Nav items feat(chrome)!: improves markup structure for Nav items Apr 10, 2024
@geotrev geotrev merged commit 0996d8f into next Apr 10, 2024
5 checks passed
@geotrev geotrev deleted the george/chrome-navitems branch April 10, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants