USWDS - Core: Repair color contrast issues for color-grade 45 #4694
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes #4146.
Problem details:
Background colors with a color-grade of 45 will produce inaccurate results when fed into the
get-color-token-from-bgmixin. Two distinct issues have been identified and are outlined below:Note: Color-grade 45 is a mid-range grade given to any color with a relative luminance (rLum) value of 0.183 < rLum < 0.25.
ink#1b1b1b(ie, have a contrast ratio >4.5:1) but our system returns a warning that neitherwhitenorinkis accessible, and returns the preferred token (whiteby default)#7a8677#629739whiteorink(ie, have a contrast ratio <4.5:1 when tested against both colors)#577c8e#7e847dTesting revealed that rLum = 0.225 is the breakpoint that separates the two issues. You can see the errors shift in the following
@debugresults, which include sample colors with specific rLUM values as well as notes from manual contrast testing with the WebAIM contrast checker:Proposed solution:
To solve, we must:
$bg-colorfor color-grade 45 and serve positive results "black" and "white" contrast tokensResults after implementing this solution:
Note the shift in calculate-grade results. Some items that were color-grade 45 are now color-grade 40. Color-grade 45 now receives
blackfor contrast tokenAdditional information
To reproduce original issue:
$theme-color-accent-cool:to#5E9732 !default;inpackages/uswds-core/src/styles/settings/_settings-color.scssWarning: [Button] Neither the specified preferred color token (
white) nor the fallback color token (ink) have AA contrast on aaccent-coolbackground. Usingwhite. Please check your source code and project settings.npm testand make sure the tests for the files you have changed have passed.