Skip to content

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Dec 13, 2023

Summary

Fixed a bug that caused some grid utility classes to be ignored when used inside usa-footer. Resolves style specificity issues between usa-footer and usa-grid-layout. This resolves visual regressions potentially caused by #5289.

Breaking change

This is not a breaking change.

Related issue

Closes #5676

Related pull requests

Changes implemented in #5289

Preview link

Footer →

Demo repo →

Demo footer →

Problem statement

Layout grid styles defined in footer have higher specificity than other layout-grid styles. As a result, updated layout grid utility classes in footer markup do not affect layout as expected.

Solution

Tip

The files changed may look confusing, but it simply moves the styles above the .footer{} declaration instead of nesting them.

Move layout grid classes above .footer class.

Example

// Grid styles ported over to remove dependency
.grid-row {
@include grid-row;
}
// Gaps
.grid-gap {
@include grid-gap;
}
.grid-gap-1 {
@include grid-gap(1);
}
.grid-gap-2 {
@include grid-gap(2);
}
.grid-gap-4 {
@include grid-gap(4);
}

Testing and review

The demo repo below showcases how footer-defined grid styles have specificity over standard grid classes when both are imported to a project.

  1. Checkout and start this test repo on your local machine
    • By default, this test repo uses 3.7.1
    • Imports both footer and grid-layout
  2. Inspect markup for both footers
    • Top footer features a mobile utility class which is found in footer and a desktop utility class found in grid-layout
    • Bottom footer features two utility classes, neither of which are included in footer css
  3. In desktop width viewports
    • Note that the top footer breaks only one link to second line.
    • The bottom footer has all links in one column.
  4. Inspect <li> style changes
    • Note that the footer defined classes take priority, despite layout-grid being included
  5. Install this branch
    • npm install @uswds/uswds "https://github.com/uswds/uswds/tree/cm-footer-grid-hotfix" --save
  6. Trigger sass rebuild
  7. Hard refresh the page
  8. Resize window and view changes
    • Note that both footers now break links into two columns with two rows on desktop widths
  9. Inspect styles at breakpoints
  10. Layout grid classes should now apply as expected

Testing checklist

  • Layout grid utility classes work as expected
  • Footer styles no longer take priority
  • Confirm there is no issue with non-nested gird classes in _usa-footer.scss
  • $theme-layout-grid-use-important: true is not required for desired layout-grid styles

Further consideration

I considered investigating a sass:meta test to check for the inclusion of grid-layout and nest the footer grid classes within that but figured this would be enough for a hotfix/mvp.

Alternatively, we could investigate using a theme setting to enable/disable these styles. I opt for a logic test (if possible) so users are not required to take an extra step other than importing grid-layout

Comment on lines +119 to +120
> .grid-container {
@include grid-container($theme-footer-max-width);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving .grid-container class to match what it was in 3.7.0 before changes were made.

.usa-footer {
@include border-box-sizing;
@include typeset($theme-footer-font-family);
overflow: hidden;
> .grid-container {
@include grid-container($theme-footer-max-width);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@mahoneycm to confirm, the current state has them outside and this change brings them back under footer class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current state has all of the grid classes nested under the footer class. This change moves them outside of the footer class to resolve specificity issues.

I maintained .usa-footer > .grid-container to match 3.7.0

@mahoneycm mahoneycm marked this pull request as ready for review December 14, 2023 18:29
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.

@mahoneycm a few questions:

  1. Does this create duplicate styles in the final CSS file?
  2. If so, is there a negative impact on performance?
  3. Is there a method that can help us avoid specificity issues or duplicating styles (for example: :where() — baseline browser support or a flag to check if grid sass has loaded) ?

Here's how I understand the issues:

  1. The specificity negatively impacts users.
  2. Guidance is needed to direct users to load usa-layout-grid.

Is that correct?

@mahoneycm
Copy link
Contributor Author

mahoneycm commented Jan 26, 2024

@mejiaj

Question response

1. Does this create duplicate styles in the final CSS file?

  • Yes

2. If so, is there a negative impact on performance?

  • It doesn't appear so
    • develop - styles.css size: 640.05kb
    • Fix - styles.css size: 639.56kb

3. Is there a method that can help us avoid specificity issues or duplicating styles (for example: :where() — baseline browser support or a flag to check if grid sass has loaded) ?

  • :where()
    • Using :where() does seem to resolve style conflicts but it looks like we’ll have to use it on every grid class definition in footer.scss to negate specificity. How do you feel about that?
  • sass:meta
    • I tried looking into a few sass:meta logic checks but since the classes are still being included in the uswds package the checks return true
    • I believe a check like this would have to happen on the project level before being compiled into CSS.

Issues

1. The specificity negatively impacts users.

  • Precisely.
  • Ex.) If a user set a new desktop grid utility class, the mobile definition from footer would win the specificity check.

2. Guidance is needed to direct users to load usa-layout-grid.

  • Yes.
  • If users plan to use layout-grid classes that are not standard to our variants, they will need to load usa-layout-grid

@mejiaj
Copy link
Contributor

mejiaj commented Jan 29, 2024

@mahoneycm thanks for looking into my questions.

We should have guidance about the layout grid dependency on the website (if we don't have it already).

For immediate solutions, using :where() as a hotfix seems clearer in our intention to add layout support without needing to duplicate, override, or create specificity issues.

If you'd like to discuss with the team further please add the Discussion label and we can discuss in Slack or in Dev Sync.


Long term, I like the idea of a flag to check if layout grid is loaded. We'll have to see what additional components rely heavily on layout grid.

@mahoneycm

This comment was marked as outdated.

@mahoneycm mahoneycm closed this Jan 30, 2024
@mahoneycm mahoneycm reopened this Feb 8, 2024
@mahoneycm
Copy link
Contributor Author

Reopened based on the discussion in Dev sync - Release check-in 🔒 (only GSA emails).

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.

Thanks for re-opening this. Tested in DigitalGov and locally. No issues found.


I've modified the PR description to improve clarity on what changed by adding a code example.

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.

Looking good! Just one small note about aligning .grid-gap output with the current CSS. Not sure if it is necessary but wanted to flag for consideration.

  • Confirm no visual regressions with default view
  • Confirm that various desktop grid classes work as expected
  • Confirm that various mobile-lg grid classes work as expected
  • Confirm that various tablet grid classes work as expected

@mahoneycm mahoneycm requested a review from amyleadem February 21, 2024 15:29
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.

Looks good to me!

@amyleadem amyleadem requested a review from thisisdano February 21, 2024 15:49
@thisisdano thisisdano merged commit b741317 into develop Feb 27, 2024
@thisisdano thisisdano deleted the cm-footer-grid-hotfix branch February 27, 2024 00:25
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 - Bug: Removing layout-grid dependency causes style conflicts.
4 participants