-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Settings: Update sass map pattern #5216
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
Conversation

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.
A nice enhancement! I tested in uswds-sandbox
and can confirm:
- Settings for
mobile
andcard
are specified insrc/_styles/_uswds-theme.scss
- Settings are added to the defaults, giving me 5 total breakpoints (from three)
- Removing the overrides for
mobile
andcard
will fallback to default (mobile-lg, tablet, desktop
) -
⚠️ Passing an invalid breakpointjumbo: true
results in no errors. Current behavior ondevelop
.
BTW, instead of manually linking via npm link
you can install a git branch directly. You just need to run npm i "uswds/uswds#cm-theme-setting-maps"
in your test branch.
Just a few requests:
- The description marks this as potentially breaking, could you add examples of where this would be a breaking change?
- Can you create a PR for necessary site updates?
- Can you link that PR to this one in the related pull requests section
@mejiaj @amyleadem If we like this implementation, should I go ahead and begin to look updating other maps to match this pattern? The reason I ask, is because of the note I want to update on Site about updating all values of a map.
I feel like the best route is to make updating map values uniform across the board so we only need to offer guidance on map settings once. @mejiaj to answer your question of where this would be a breaking change: Before this update, if a user updated breakpoint maps and excluded a breakpoint, it would be disabled. For example: // User defined breakpoints
$theme-utility-breakpoints: (
mobile: true,
desktop: true,
)
After this update, the default breakpoints will become enabled again despite not being defined, so the same settings as above would result in: // User defined breakpoints
$theme-utility-breakpoints: (
mobile: true,
desktop: true,
)
// Results in the following breakpoints being enabled
mobile: true,
mobile-lg: true,
tablet: true,
desktop: true I wanted to flag this because I thought it could potentially cause visual regressions for users who aren't expecting these values to become enabled. |

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.
This enhancement is great @mahoneycm! To me it makes configuring USWDS sass maps much more intuitive and the solution feels elegant. Thank you for taking this on!
I have completed the following tests:
Confirmed that editing a single value (Example: ”card”: true
):
- Adds the
card
breakpoint to the compiled CSS - Does not remove existing breakpoints (ex:
mobile-lg
) from the compiled CSS
This is up for debate, but I do think this functionality should be consistent across all USWDS settings maps before we release this enhancement. However, I haven’t fully investigated what would need to be included in that, so it might make sense to work on it in more than one PR and potentially release incrementally.
Additionally, we should prepare the following documentation updates before merging:
- Add a summary of the break in the PR description so users can easily find what they need to check/fix
- Consider adding a comment in
_settings-utilities.scss
that lets users know that they should update$theme-utility-breakpoints
in their settings config and not$theme-utility-breakpoints-complete
. - Check all references to
$theme-utility-breakpoints
in uswds-site - Update or remove the note
When modifying any settings stored as a map, you need to set *all* elements of the map, not just the element you wish to change.
in uswds-site - Add changelog items for the Settings page and any affected utility pages. The changelog should indicate what might possibly break.
@@ -28,7 +28,8 @@ used by utilities or layout grid | |||
---------------------------------------- |
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.
I am wondering if it would be helpful if we added a note here that users should edit $theme-utility-breakpoints
in the settings configuration and not $theme-utility-breakpoints-complete
.
Added @use 'sass:map' to _settings.general.scss as required to use function Updated all existing references of -namespace to -namespace-complete
map-merge() is outdated and no longer recommended by Sass
@amyleadem @mejiaj Ready for re-review! Restructured the PR to reflect all the sass maps affected and not just breakpoints! |
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.
This is great, @mahoneycm! I am excited about this update. I also really appreciate the test pages you set up. They were very helpful. Good work!
I performed the following tests:
- Confirmed that customizing the value of a single map key affects only the designated key and does not affect other items in the map. Tested the following settings:
- $theme-utility-breakpoints
- $theme-namespace
- $background-color-settings
- $border-color-settings
- Confirmed all Sass maps inside
packages/uswds-core/src/styles/settings/
have been updated- Confirmed all settings maps have been updated with
map.merge
ormap.deep-merge
and each have a-complete
sibling - Confirmed all original utility settings and defaults are still there and that their defaults have not changed
- Confirmed all settings maps have been updated with
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.
A nice improvement. I've tested:
- References are accurate and up-to-date.
- Selected breakpoints can be overridden without issues.
@thisisdano ready for final review! |
A great improvement! |
Summary
Updates sass map pattern to allow users to only define overrides while keeping defaults for the other values
Breaking change
This is potentially a breaking change.
Previously, if a user left an item out of a map, it would be set to
false
and thus deactivating it. After this update, an item left out of the map will maintain its default value.If users deactivated certain settings by not declaring them, this update will cause those variables to be activated. Note that we did not recommend that pattern, but it's possible for users to have done so on their own
Related issue
Closes #5215
Related pull requests
Update sass map instructions on utility pages: uswds/uswds-site#2077
Problem statement
Currently, if you choose to update a USWDS setting within a sass map, you must define each setting within the map even if you are keeping the default values for the other.
Solution
We can use map-merge with a default values map to only replace updated settings keys without needing to redefine default values.
This solution
This PR updates
$theme-[map-name]
s to$theme-[map-name]-complete
wherever the setting is called.This allows users still use existing setting names, such as
$theme-utility-breakpoints
, to update which breakpoints are active, while using the-complete
map to restore defaults to undefined elements.Updated maps
$theme-namespace
$theme-utility-breakpoints
$[utility-module]-settings
Ignored maps
These maps were either, empty, set to
false
by default, or only had example values. In all three settings, we would want the users override to be the only value, which is currently how they are set up.$theme-fontface-tokens
$theme-font-[family]-src
$[utility-module]-manual-calues
Testing and review
npm run start
on the test repo_uswds-theme.scss
and expirament enabling/disabling different settingsThese tests are simple and mostly just enable different background colors as a quick visual feedback. Feel free to experiment with other utility settings to verify the new pattern is working!
Default maps for reference:
Breakpoints
Namespace
Before opening this PR, make sure you’ve done whichever of these applies to you:
git pull origin [base branch]
to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch isdevelop
).npm run prettier:scss
to format any Sass updates.