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): do not check contrast for inert elements #3894

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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