Skip to content

Commit

Permalink
fix(color-contrast): allow disabled label children
Browse files Browse the repository at this point in the history
Closes #596
  • Loading branch information
Marcy Sutton committed Dec 12, 2017
1 parent af0050f commit 6fcaf93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/color-contrast-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (nodeName === 'LABEL' || nodeParentLabel) {
return false;
}

var candidate = node.querySelector('input:not([type="hidden"]):not([type="image"])' +
var candidate = relevantNode.querySelector('input:not([type="hidden"]):not([type="image"])' +
':not([type="button"]):not([type="submit"]):not([type="reset"]), select, textarea');
if (candidate && candidate.disabled) {
return false;
Expand Down
10 changes: 10 additions & 0 deletions test/rule-matches/color-contrast-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,17 @@ describe('color-contrast-matches', function () {
fixture.innerHTML = '<input type="text" disabled>';
var target = fixture.querySelector('input');
assert.isFalse(rule.matches(target));
});

it('should not match a disabled implicit label child', function () {
fixture.innerHTML = '<label>' +
'<input type="checkbox" style="position: absolute;display: inline-block;width: 1.5rem;height: 1.5rem;opacity: 0;" disabled checked>' +
'<span style="background-color:rgba(0, 0, 0, 0.26);display:inline-block;width: 1.5rem;height: 1.5rem;" aria-hidden="true"></span>' +
'<span style="color:rgba(0, 0, 0, 0.38);" id="target">Baseball</span>' +
'</label>';
var target = fixture.querySelector('#target');
var result = rule.matches(target);
assert.isFalse(result);
});

it('should not match <textarea disabled>', function () {
Expand Down

0 comments on commit 6fcaf93

Please sign in to comment.