Skip to content

Commit

Permalink
Merge pull request #413 from dequelabs/sd/color-contrast-matches
Browse files Browse the repository at this point in the history
Shadow DOM support for color contrast matches
  • Loading branch information
dylanb authored Jul 13, 2017
2 parents 85deffa + 3a5be92 commit 3087e90
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/commons/text/visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ text.visible = function (element, screenReader, noRecursing) {
for (index = 0; index < length; index++) {
child = childNodes[index];

if (child.actualNode.nodeType === 3) {
if (child.actualNode.nodeType === 3) { // filter on text nodes
nodeValue = child.actualNode.nodeValue;
if (nodeValue && dom.isVisible(element.actualNode, screenReader)) {
result += nodeValue;
Expand Down
1 change: 1 addition & 0 deletions lib/rules/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"globals": {
"results": true,
"node": true,
"virtualNode": true,
"options": true,
"axe": true
},
Expand Down
17 changes: 9 additions & 8 deletions lib/rules/color-contrast-matches.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* global document */

var nodeName = node.nodeName.toUpperCase(),
nodeType = node.type,
doc = document;
nodeType = node.type;

if (node.getAttribute('aria-disabled') === 'true' || axe.commons.dom.findUp(node, '[aria-disabled="true"]')) {
return false;
Expand Down Expand Up @@ -40,41 +39,43 @@ if (nodeName === 'LABEL' || nodeParentLabel) {
relevantNode = nodeParentLabel;
}
// explicit label of disabled input
let doc = axe.commons.dom.getRootNode(relevantNode);
var candidate = relevantNode.htmlFor && doc.getElementById(relevantNode.htmlFor);
if (candidate && candidate.disabled) {
return false;
}

var candidate = node.querySelector('input:not([type="hidden"]):not([type="image"])' +
var candidate = axe.utils.querySelectorAll(virtualNode, 'input:not([type="hidden"]):not([type="image"])' +
':not([type="button"]):not([type="submit"]):not([type="reset"]), select, textarea');
if (candidate && candidate.disabled) {
if (candidate.length && candidate[0].actualNode.disabled) {
return false;
}

}

// label of disabled control associated w/ aria-labelledby
if (node.id) {
let doc = axe.commons.dom.getRootNode(node);
var candidate = doc.querySelector('[aria-labelledby~=' + axe.commons.utils.escapeSelector(node.id) + ']');
if (candidate && candidate.disabled) {
return false;
}
}

if (axe.commons.text.visible(node, false, true) === '') {
if (axe.commons.text.visible(virtualNode, false, true) === '') {
return false;
}

var range = document.createRange(),
childNodes = node.childNodes,
childNodes = virtualNode.children,
length = childNodes.length,
child, index;

for (index = 0; index < length; index++) {
child = childNodes[index];

if (child.nodeType === 3 && axe.commons.text.sanitize(child.nodeValue) !== '') {
range.selectNodeContents(child);
if (child.actualNode.nodeType === 3 && axe.commons.text.sanitize(child.actualNode.nodeValue) !== '') {
range.selectNodeContents(child.actualNode);
}
}

Expand Down
Loading

0 comments on commit 3087e90

Please sign in to comment.