Skip to content

Commit d77c885

Browse files
authored
fix(color-contrast): do not run on elements with font-size: 0 (#4822)
Closes #4820
1 parent c7e2c1c commit d77c885

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/rules/color-contrast-matches.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ function colorContrastMatches(node, virtualNode) {
137137
return false;
138138
}
139139

140+
if (!parseFloat(virtualNode.getComputedStylePropertyValue('font-size'))) {
141+
return false;
142+
}
143+
140144
const range = document.createRange();
141145
const childNodes = virtualNode.children;
142146
for (let index = 0; index < childNodes.length; index++) {

test/integration/rules/color-contrast/color-contrast.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,10 @@
465465
<div id="ignore13" style="padding-left: 65px">Hello World</div>
466466
</div>
467467
</div>
468+
469+
<div
470+
id="ignore13"
471+
style="background-color: gray; color: white; font-size: 0; font-weight: bold"
472+
>
473+
Ignore.
474+
</div>

test/rule-matches/color-contrast-matches.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ describe('color-contrast-matches', function () {
431431
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
432432
});
433433

434+
it('should not match text with font-size: 0', () => {
435+
fixture.innerHTML = '<div style="font-size: 0">hi</div>';
436+
const target = fixture.querySelector('div');
437+
axe.testUtils.flatTreeSetup(fixture);
438+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
439+
});
440+
434441
if (shadowSupport) {
435442
it('should match a descendant of an element across a shadow boundary', function () {
436443
fixture.innerHTML =

0 commit comments

Comments
 (0)