-
Notifications
You must be signed in to change notification settings - Fork 779
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
fix(color-contrast): check bg on fg contrast for thin text-shadows #3350
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.
To see the results locally go to http://localhost:9876/test/integration/rules/color-contrast/text-shadows.html
The script on that page adds icons to what passes and what fails.
contrastContributor = | ||
bgContrast > fgContrast ? 'shadowOnBgColor' : 'fgOnShadowColor'; | ||
// Compare shadow, bgColor, textColor. Check passes if any is sufficient | ||
const fgBgContrast = getContrast(bgColor, fgColor); |
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 the critical change here. Considering fgColor / bgColor contrast even if there's a thin shadow.
@@ -17,7 +17,7 @@ | |||
} | |||
}, | |||
"pseudoSizeThreshold": 0.25, | |||
"shadowOutlineEmMax": 0.1 | |||
"shadowOutlineEmMax": 0.2 |
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.
After asking a few people I discovered the current threshold was slightly too strict. Increasing this number means the slightly larger shadows will be allowed to serve as text outlines, giving more opportunities for it to pass the contrast ratio.
@@ -303,220 +320,433 @@ | |||
<section class="s1" id="b1"> | |||
<div class="r0"><i id="sample1">Sample</i></div> | |||
<div class="r1"> | |||
<i>b1-r1-i1</i> <i>b1-r1-i2</i> <i>b1-r1-i3</i> <i>b1-r1-i4</i> | |||
<i id="b1-r1-i1">b1-r1-i1</i> |
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 added IDs to make these easier to work with.
The initial text-shadow implementation overlooked that the shadow color can have the luminance between that of the foreground and background. Now, if you have a dark text, light background and a thin shadow that sits in between those two colors, axe will grab the contrast of the foreground and background color.
Related to that, the shadowOutlineEmMax threshold is bumped to .2em. I've showed a few people the .15em example and most seemed okay with comparing background and foreground for a shadow of that width.
This change also addressed some "false positive" edge cases, making the rule in general slightly more permissive when it comes to text-shadow.
Closes issue: #3157