Skip to content

fix(color-contrast): check bg on fg contrast for thin text-shadows#3350

Merged
WilcoFiers merged 2 commits intodevelopfrom
shin-text-shadow-contrast
Jan 14, 2022
Merged

fix(color-contrast): check bg on fg contrast for thin text-shadows#3350
WilcoFiers merged 2 commits intodevelopfrom
shin-text-shadow-contrast

Conversation

@WilcoFiers
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

},
"pseudoSizeThreshold": 0.25,
"shadowOutlineEmMax": 0.1
"shadowOutlineEmMax": 0.2
Copy link
Copy Markdown
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.

<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
Copy Markdown
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