Skip to content

Commit

Permalink
fix(color-contrast): do not check contrast on elemets that are inerted (
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jan 26, 2023
1 parent cef96be commit da19946
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/rules/color-contrast-matches.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* global document */
import { getAccessibleRefs } from '../commons/aria';
import { findUpVirtual, visuallyOverlaps, getRootNode } from '../commons/dom';
import {
findUpVirtual,
visuallyOverlaps,
getRootNode,
isInert
} from '../commons/dom';
import {
visibleVirtual,
removeUnicode,
Expand Down Expand Up @@ -35,7 +40,7 @@ function colorContrastMatches(node, virtualNode) {
return false;
}

if (isDisabled(virtualNode)) {
if (isDisabled(virtualNode) || isInert(virtualNode)) {
return false;
}

Expand Down
8 changes: 8 additions & 0 deletions test/integration/rules/color-contrast/color-contrast.html
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,11 @@
<span id="pass22">This div will be on top of the stack</span>
</div>
</div>

<div id="ignore11" style="background: #000; color: #333" inert>hello</div>

<div inert>
<div>
<div id="ignore12" style="background: #000; color: #333">hello</div>
</div>
</div>
14 changes: 14 additions & 0 deletions test/rule-matches/color-contrast-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ describe('color-contrast-matches', function () {
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
});

it('should not match inert', function () {
fixture.innerHTML = '<div inert>hi</div>';
var target = fixture.querySelector('div');
axe.testUtils.flatTreeSetup(fixture);
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
});

it('should not match a descendant of inert', function () {
fixture.innerHTML = '<div inert><span>hi</span></div>';
var target = fixture.querySelector('span');
axe.testUtils.flatTreeSetup(fixture);
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
});

if (shadowSupport) {
it('should match a descendant of an element across a shadow boundary', function () {
fixture.innerHTML =
Expand Down

0 comments on commit da19946

Please sign in to comment.