Skip to content
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

Merged
merged 2 commits into from
Jan 14, 2022

Conversation

WilcoFiers
Copy link
Contributor

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

@WilcoFiers WilcoFiers requested a review from a team as a code owner January 13, 2022 11:43
Copy link
Contributor Author

@WilcoFiers WilcoFiers left a 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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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>
Copy link
Contributor Author

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.

@WilcoFiers WilcoFiers merged commit d92a7e5 into develop Jan 14, 2022
@WilcoFiers WilcoFiers deleted the shin-text-shadow-contrast branch January 14, 2022 09:34
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.

2 participants