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

USWDS - Header: Vertically center icon in nav #5654

Merged
merged 7 commits into from Dec 8, 2023

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Dec 4, 2023

Summary

Fixed the vertical alignment of the expand icon on header navigation items.

Related issue

Closes #5660

Preview link

Header component

Related PR

This work originated in #5267 (Thanks @aduth!)
Changelog →

Problem statement

When navigation links include text which breaks to multiple lines (particularly in mobile navigation), the expander icon is shown at the bottom right of the link, which makes it more difficult to identify.

Solution

Vertically center the icon.

Before After
Screen Shot 2023-05-02 at 10 51 40 AM Screen Shot 2023-05-02 at 10 52 04 AM

Testing and review

  1. Visit header variant pages
  2. Inspect mobile styles
  3. Create large link span for accordion buttons
  4. Confirm expander icon maintains vertical alignment

Testing checklist

  • Mobile navigation expander icons maintain vertical alignment
  • No visual regression in desktop variants

@amyleadem amyleadem changed the title Feature vertically center nav elements USWDS - Header: Vertically center icon in mobile nav Dec 8, 2023
@mahoneycm mahoneycm marked this pull request as ready for review December 8, 2023 16:46
Comment on lines +225 to +234
&[aria-expanded] {
span {
@include place-icon($-add-icon, "after");

&::after {
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[aria-expanded] vs accordion-button

Originally commented on #5655

Im curious if it would make more sense if we moved these lines to usa-nav__primary.usa-accordion__button.span on line 300 instead of [aria-expanded]. Seems like it might be a bit more descriptive but it is further away from the other aria-expanded=true/false styles which are relevant to this work.

.usa-accordion__button {
span {
@include at-media($theme-header-min-width) {
margin-right: 0;
padding-right: units(2);
}
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

In future work this type of research should be part of the initial stages. This will help us write more maintainable code and robust features.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with James's point. We don't need to change this work, but tying our styles to ARIA roles is something that may not stand the test of time

@amyleadem amyleadem added this to the uswds 3.7.1 milestone Dec 8, 2023
Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

This is looking good to me. I tested the following in Safari, Chrome, and Firefox:

  • Confirm icon is vertically centered in mobile with two lines of text
    image
  • Confirm icon is vertically centered in desktop with two lines of text
    image
  • Confirm icon is vertically centered in mobile with one line of text
  • Confirm icon is vertically centered in desktop with one line of text
  • Confirm icon is correctly aligned when item is expanded
  • Confirm no regressions in hover state colors in both desktop and mobile
  • Confirm no regressions in high contrast mode in both desktop and mobile
  • Confirmed for all variants of the header

@mejiaj mejiaj changed the title USWDS - Header: Vertically center icon in mobile nav USWDS - Header: Vertically center icon in nav Dec 8, 2023
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

No visual regressions found on Chromium mobile/desktop.

I removed mobile from the title because this PR mentions mobile nav, but the styles apply for all breakpoints.

@thisisdano thisisdano merged commit 8892747 into develop Dec 8, 2023
5 checks passed
@thisisdano thisisdano deleted the feature-vertically-center-nav-elements branch December 8, 2023 20:51
@thisisdano thisisdano mentioned this pull request Dec 8, 2023
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.

USWDS - Nav: Mobile expander button icons are not centered
5 participants