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 - Nav: Resolve padding overflow bug #5655
Conversation
…swds/uswds into cm-vertical-venter-nav-padding-fix
…swds/uswds into cm-vertical-center-nav-padding-fix
…ical-center-nav-padding-fix
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.
Looks good, thank you. Tested mobile and desktop for regressions on chromium.
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.
@mahoneycm I noticed that changing the display to inline-block
caused the nav items to change height, which results in the submenu to jump up and down if one nav item is taller than another:
I quickly played with a possible fix and found that adding the following restores the height. The following code renders the screenshot below.
.usa-nav__primary {align-items:stretch}
.usa-nav__primary button {height:100%}
It might also be worth exploring alternatives to inline-block
as well.
Once this issue is addressed, I'll test some more to make sure it doesn't have a risk for inadvertent changes.
@amyleadem Thank you so much for spotting that! Definitely an improvement and will prevent any weird click area issues. After some testing, I noticed that the last nav item (the link) could become uncentered if another button's text breaks into three lines. This seems unlikely at the current font size but possible if a user were to override the nav link sizes. I toyed with it for a while but was unable to get the link to maintain its vertical alignment without updating markup. I was hoping to find a solution to center the items while maintaining the full height but was unable to, unfortunately. Do you think this is enough of an edge case to not worry about? It seems unlikely to me but I was hoping to cover all our bases. |
…om/uswds/uswds into cm-vertical-center-nav-padding-fix
&[aria-expanded] { | ||
span { | ||
display: inline-block; | ||
|
||
&::after { | ||
position: absolute; | ||
top: 50%; |
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.
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.
uswds/packages/usa-nav/src/styles/_usa-nav.scss
Lines 307 to 315 in 05e4ee2
.usa-accordion__button { | |
span { | |
@include at-media($theme-header-min-width) { | |
margin-right: 0; | |
padding-right: units(2); | |
} | |
} | |
} | |
} |
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.
Redundant media query
Unrelated to this work but it looks like we have a duplicate media query on line 291
.
uswds/packages/usa-nav/src/styles/_usa-nav.scss
Lines 286 to 300 in 05e4ee2
@include at-media($theme-header-min-width) { | |
background-image: none; | |
background-color: color("primary-darker"); | |
color: color("white"); | |
@include at-media($theme-header-min-width) { | |
span { | |
@include place-icon($expand-less-icon, "after"); | |
&::after { | |
right: units(1.5); | |
background-color: white; | |
@media (forced-colors: active) { | |
background-color: ButtonText; | |
} | |
} |
…swds/uswds into cm-vertical-center-nav-padding-fix
…om/uswds/uswds into al-vertical-center-nav-padding-fix
Dismissing this review because the PR has changed.
> button, | ||
> a { | ||
@include at-media($theme-header-min-width) { | ||
height: 100%; | ||
} |
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.
Caution
Selectors like this are heavy handed and could cause breaking changes. Acceptable because this component heavily relies on this pattern. We should use this with a lot of caution.
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.
Tested the following in Chrome, Safari, and Firefox at desktop widths.
- Navbar items align to vertical center when one item spans multiple lines and other items span one line. Also confirm that all navbar elements are the same height regardless of text height.
- Test when current item is two lines, other items one line
- Test one non-current item is two lines, others are one line
- Test when simple link is two lines, others are one line
- Navbar items align to vertical center when all items are one line
- No changes from
develop
except a small shift in icon location
- No changes from
- Navbar items align to vertical center when all items span multiple lines
- The code affects only the mobile presentation.
- All changes are inside the $theme-header-min-width breakpoint
- Everything still works after pulling in USWDS - Header: Vertically center icon in nav #5654
Summary
Fixed a bug that caused long nav button spans to overflow into its padding. Now, nav buttons properly break into two lines and maintain center alignment.
Breaking change
This is not a breaking change.
Related issue
Closes #5656
Related pull requests
#5267
Changelog →
Preview link
All headers demo →
Header storybook preview →
Problem statement
When navigation button spans cause a line break, their text flows into their padding instead of breaking onto a new line
Solution
span
element todisplay: inline-block
usa-nav__primary
child item flex alignment tocenter
Testing and review
Testing checklist
Further considerations
Note
There seems to be a CSS behavior that causes a width calculation quirk and leaves empty space between the span and the icon. This behavior is present on
develop
.I briefly tried resolving but didn't find any quick solutions. Do we think this is out of scope or should we dig deeper?