-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add shadow dom support to color contrast rule
* chore: move isShadowRoot to its own file * fix: add shadow dom support to color contrast rule Closes #687 * test(color): add tests, incorporate feedback * feat: move shadowElementsFromPoint to commons.dom * test: upgrade to circle 2.0 and try failing tests again
- Loading branch information
1 parent
4114833
commit 0440c9b
Showing
14 changed files
with
800 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* global axe, dom */ | ||
/** | ||
* Get elements from point across shadow dom boundaries | ||
* @method shadowElementsFromPoint | ||
* @memberof axe.commons.dom | ||
* @instance | ||
* @param {Number} nodeX X coordinates of point | ||
* @param {Number} nodeY Y coordinates of point | ||
* @param {Object} [root] Shadow root or document root | ||
* @return {Array} | ||
*/ | ||
dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document) { | ||
return root.elementsFromPoint(nodeX, nodeY) | ||
.reduce((stack, elm) => { | ||
if (axe.utils.isShadowRoot(elm)) { | ||
const shadowStack = dom.shadowElementsFromPoint(nodeX, nodeY, elm.shadowRoot); | ||
stack = stack.concat(shadowStack); | ||
// filter host nodes which get included regardless of overlap | ||
// TODO: refactor multiline overlap checking inside shadow dom | ||
if (stack.length && axe.commons.dom.visuallyContains(stack[0], elm)) { | ||
stack.push(elm); | ||
} | ||
} else { | ||
stack.push(elm); | ||
} | ||
return stack; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* global axe */ | ||
|
||
const possibleShadowRoots = ['article', 'aside', 'blockquote', | ||
'body', 'div', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | ||
'header', 'main', 'nav', 'p', 'section', 'span']; | ||
/** | ||
* Test a node to see if it has a spec-conforming shadow root | ||
* | ||
* @param {Node} node The HTML DOM node | ||
* @return {Boolean} | ||
*/ | ||
axe.utils.isShadowRoot = function isShadowRoot (node) { | ||
const nodeName = node.nodeName.toLowerCase(); | ||
if (node.shadowRoot) { | ||
if (/^[a-z][a-z0-9_.-]*-[a-z0-9_.-]*$/.test(nodeName) || | ||
possibleShadowRoots.includes(nodeName)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.