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(header-menu-item): add isActive prop to apply styles to selected item #5504

Merged
merged 25 commits into from
Apr 7, 2020
Merged

feat(header-menu-item): add isActive prop to apply styles to selected item #5504

merged 25 commits into from
Apr 7, 2020

Conversation

abbeyhrt
Copy link
Contributor

@abbeyhrt abbeyhrt commented Mar 2, 2020

Closes #3674

This PR adds an isActive prop that determines which HeaderMenuItem should have aria-current="page" and its corresponding styles applied. It also edits one of the UIShell's stories to show an example of the new style. This removes the border-bottom on the Header bar since it didn't seems to be there in the design specs and it was causing a black line underneath the focus and the selected states.

Changelog

New

  • isActive prop
  • styles for selected HeaderMenuItem

Removed

  • border-bottom from the Header

Testing / Reviewing

Designers: check that the new styles are how we want to selected state to look, you can see an example of the selected state in UIShell's Header Base w/ Navigation story.

Dev: Is this how we want aria-current to be applied? BreadcrumbItem does the same thing in a different way and I'm not sure what is the best way to go about this.

@abbeyhrt abbeyhrt requested a review from a team as a code owner March 2, 2020 18:09
@ghost ghost requested review from dakahn and tw15egan March 2, 2020 18:09
@abbeyhrt abbeyhrt requested review from a team, jeanservaas and laurenmrice and removed request for a team and jeanservaas March 2, 2020 18:10
@ghost ghost removed their request for review March 2, 2020 18:10
@netlify
Copy link

netlify bot commented Mar 2, 2020

Deploy preview for carbon-elements ready!

Built with commit ca96865

https://deploy-preview-5504--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Mar 2, 2020

Deploy preview for carbon-components-react ready!

Built with commit ca96865

https://deploy-preview-5504--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Mar 2, 2020

Deploy preview for carbon-elements ready!

Built with commit 5fbfece

https://deploy-preview-5504--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Mar 2, 2020

Deploy preview for carbon-components-react failed.

Built with commit b8dc12e

https://app.netlify.com/sites/carbon-components-react/deploys/5e8bc2e90545bf0006ae63a5

@netlify
Copy link

netlify bot commented Mar 2, 2020

Deploy preview for carbon-elements ready!

Built with commit b8dc12e

https://deploy-preview-5504--carbon-elements.netlify.com

ref
) {
return (
<li className={className} role={role}>
<Link
{...rest}
aria-current={isActive ? 'page' : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would we just want them to pass in <HeaderMenuItem aria-current="page" /> as a prop? Similarly, would we want to use isActive to specify a custom selector if they don't want to use the ARIA tech? (Similar to what we do over in breadcrumbs)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just sharing an experience; Using ARIA attribute for a styling purpose has caused a breaking change when we made an a11y structure fix/change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to match the pattern we use in Breadcrumb. Thanks for the insight @joshblack and @asudoh! Definitely think not wholly on the ARIA attributes is a good way to go here 👍

Copy link
Contributor

@dakahn dakahn left a comment

Choose a reason for hiding this comment

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

Seems cool to me! Josh's questions notwithstanding

Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

The selected state looks good.

But when I click on the selected state this white bar appears above it. I think instead when clicking on it, it should be getting a white focus border.

Mar-03-2020 09-04-05

@tw15egan
Copy link
Collaborator

tw15egan commented Mar 5, 2020

@abbeyhrt small visual bug I'm noticing

header-nav

Might just need a transparent border on the inactive links?

Otherwise, the changes look great!

@tw15egan
Copy link
Collaborator

tw15egan commented Mar 9, 2020

@abbeyhrt we can try something like

  a.#{$prefix}--header__menu-item[aria-current='page']:focus,
  a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current:focus {
    border-bottom: 2px solid $shell-header-focus;
    outline: 2px solid $shell-header-focus;
  }

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Just one comment - Thanks @abbeyhrt!

// We set the current class only if `isCurrentPage` is passed in and we do
// not have an `aria-current="page"` set for the breadcrumb item
[`${prefix}--header__menu-item--current`]:
isCurrentPage && ariaCurrent !== 'page',
Copy link
Contributor

Choose a reason for hiding this comment

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

Usage of ARIA attribute content for styling has caused breaking changes during our a11y fix effort. So wondering if just isCurrentPage is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we'll run into any problems since it's being implemented in both ways. It definitely is risky to style using ARIA roles since we might change those based on new info but aria-current="page" is more stable and not likely to change. I also think it's nice to support both use cases for the ways that people might try to implement current page styling.

Copy link
Contributor

Choose a reason for hiding this comment

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

aria-current="page" is more stable and not likely to change

Probably it may change (esp. in post-IE era) because of newer spec in this area is on the horizon https://wicg.github.io/aom/explainer.html

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like it'd be good to go for now, given the class fallback. If there is a specific line or section from the spec that you think is relevant and should be included in the PR that'd be great to highlight 👍 aria-current with page seems like a fairly consistent attribute for communicating present navigation to screen readers.

@abbeyhrt abbeyhrt requested a review from laurenmrice March 11, 2020 16:31
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

I still get some jumping between links. Seems to always be when I click Link 1 and another link

Mar-11-2020 12-17-09

@abbeyhrt
Copy link
Contributor Author

@laurenmrice my bad! I didn't actually push the new changes 🤦‍♀

Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

looks great !🙌🏻

// We set the current class only if `isCurrentPage` is passed in and we do
// not have an `aria-current="page"` set for the breadcrumb item
[`${prefix}--header__menu-item--current`]:
isCurrentPage && ariaCurrent !== 'page',
Copy link
Contributor

@asudoh asudoh Mar 17, 2020

Choose a reason for hiding this comment

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

Just in case if this clarifies what the code should be:

Suggested change
isCurrentPage && ariaCurrent !== 'page',
isCurrentPage,

Copy link
Contributor

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

It seems like the ends of the line might not be straight potentially?

image

@abbeyhrt abbeyhrt requested a review from joshblack March 24, 2020 20:02
@joshblack joshblack merged commit 49e87c8 into carbon-design-system:master Apr 7, 2020
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.

Missing property and style for active HeaderMenuItem in HeaderNavigation
6 participants