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
get-token-from-bg should warn not error #3926
Comments
Could be related to #3906. |
In looking into #3906, I've updated the code to return a warning. But it will still cause an error because it will return a {
@include set-link-from-bg("base-darkest", "white");
} Error in plugin "sass"
Message:
src/stylesheets/core/mixins/_set-link-from-bg.scss
Error: "`false` is not a valid USWDS color token. See designsystem.digital.gov/design-tokens/color for more information."
╷
31 │ color: color($link-token);
│ ^^^^^^^^^^^^^^^^^^
╵
src/stylesheets/core/mixins/_set-link-from-bg.scss 31:10 set-link-from-bg() |
We are getting the following error when trying to compile: |
@astiefvater would you mind sharing your theme colors? You can find them in |
Hi James it is the text file attached to my original comment. It would not let me upload with the .scss extension. Let me know if that won't convert back for some reason though. |
My apologies. Thanks for that. |
I think the core problem is that the function iterates over a list of tokens for find a suitable match, but fails is no suitable match is found. One solution might be to store the comparison outputs to an array, run comparisons to the magic number, then return the best one by comparison and log a warning if it's not in the threshold.
|
@plummer-flex you can find more details in the thread on #3906 (comment). I like the proposal and I think it could be part of the solution. There are a few more things I think we can fine-tune to produce more reliable results. Right now I'm looking at how the luminance numbers are generated and why some colors that are accessible still fail. |
Yeah, I guess it's two issues.
Godspeed. |
Case 1Colors: $theme-color-base-lightest: #f2f2f2;
$theme-color-base-lighter: #dcdcdc;
$theme-color-base: #707070;
$theme-color-base-dark: #535353;
$theme-color-base-darkest: #141414;
$theme-color-base-ink: #141414; Using: @include set-link-from-bg("red-warm-60v", "ink", "base-lighter"); TestsInk❌
This one fails automatically so we can move on to Base lighter❌
Both custom
But fail in our tests. In our code it looks like: // $color-token: base-lighter
// $lum: 0.709
// $min: 0.75
// $max: 0.82
// $next-max: 0.65
@if $next-max and ($lum < $min) and ($lum > $next-max) {
@return $grade + 4.9;
} Case 2Colors $theme-color-accent-warm: #ff6839;
$theme-color-base-ink: #292a2b; Using @include set-text-and-bg("accent-warm"); TestsWhite❌White
Ink❌ Ink
NoteFor buttons, like this case, there are also more considerations. The same So your initial default component could pass, but the SCSS would still fail because the active states are failing. I feel like this is important to note since we've seen many defaults passing on https://contrast-ratio.com I wasn't able to reproduce the error on #3926 (comment) ConclusionThese test cases reveal something interesting in the way we calculate grades in We need to audit |
PR merged and closing issue 2/9 |
Describe the bug
When upgrading a project using an existing USWDS theme, the theme fails to compile due to a color contrast issue. The contrast failure output does not match manual testing of the colors referenced in the error. This leads to the supposition that the function used to verify color contrast does not return a correct result.
Steps to reproduce the bug
Set
$accent-warm: #ff6839;
Set
$base-ink: #292a2b;
Compile returns error
SassError: Neither 'white' nor 'ink' have AA contrast on a 'accent-warm' background.
Expected behavior
At the least, the function should throw a warning instead of an error. While the utility of the system preventing a user from creating a non-compliant color combination has merit, this decision should ultimately be in the hands of the user.
System setup
The text was updated successfully, but these errors were encountered: