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 - Nav: Resolve padding overflow bug #5655

Merged
merged 14 commits into from Dec 8, 2023

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Dec 4, 2023

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

image

Solution

  • Set the span element to display: inline-block
  • Update usa-nav__primary child item flex alignment to center

Testing and review

  1. Visit the testing repo or Header storybook preview story
  2. In desktop views:
    1. Confirm larger spans do not overflow into padding area
    2. Confirm icons maintain center alignment
    3. Confirm nav buttons maintain equal size
    4. Confirm appropriate default and hover states
  3. In mobile views:
    1. Confirm there is no visual regression
    2. Confirm icons are vertically aligned

Testing checklist

  • Long nav button spans do not break center alignment
  • Buttons maintain equal size when one span breaks into two lines
  • Mobile styles are unaffected
  • Hover state is unaffected
  • No visual regressions

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?

Screenshot 2023-12-05 at 1 39 36 PM
Screenshot 2023-12-05 at 2 20 21 PM

@mahoneycm mahoneycm changed the title Cm vertical center nav padding fix USWDS - Nav: Resolve padding overflow bug Dec 5, 2023
@mahoneycm mahoneycm marked this pull request as ready for review December 5, 2023 21:02
@amyleadem amyleadem linked an issue Dec 6, 2023 that may be closed by this pull request
mejiaj
mejiaj previously approved these changes Dec 6, 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.

Looks good, thank you. Tested mobile and desktop for regressions on chromium.

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.

@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:

image

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%}
image

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.

@mahoneycm
Copy link
Contributor Author

@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.

image

image

Comment on lines 227 to 233
&[aria-expanded] {
span {
display: inline-block;

&::after {
position: absolute;
top: 50%;
Copy link
Contributor Author

@mahoneycm mahoneycm Dec 7, 2023

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.

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

Copy link
Contributor Author

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.

@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;
}
}

@amyleadem amyleadem dismissed mejiaj’s stale review December 8, 2023 19:43

Dismissing this review because the PR has changed.

@mejiaj mejiaj self-requested a review December 8, 2023 20:11
Comment on lines +176 to +180
> button,
> a {
@include at-media($theme-header-min-width) {
height: 100%;
}
Copy link
Contributor

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.

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.

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
  • 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

Base automatically changed from feature-vertically-center-nav-elements to develop December 8, 2023 20:51
@thisisdano thisisdano merged commit fed2fe2 into develop Dec 8, 2023
3 checks passed
@thisisdano thisisdano deleted the cm-vertical-center-nav-padding-fix branch December 8, 2023 21:23
@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 - Header: Line breaks cause text to overflow into padding area
4 participants