-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow hidden-content to work through shadow DOM bounds
- Loading branch information
1 parent
a76db4c
commit 789d62e
Showing
5 changed files
with
110 additions
and
28 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 |
---|---|---|
@@ -1,27 +1,42 @@ | ||
/*global dom, aria, axe */ | ||
/*global dom, aria */ | ||
const hiddenTextElms = [ | ||
'HEAD', 'TITLE', 'TEMPLATE', 'SCRIPT','STYLE', | ||
'IFRAME', 'OBJECT', 'VIDEO', 'AUDIO', 'NOSCRIPT' | ||
]; | ||
|
||
function hasChildTextNodes (elm) { | ||
if (!hiddenTextElms.includes(elm.actualNode.nodeName.toUpperCase())) { | ||
return elm.children.some(({ actualNode }) => ( | ||
actualNode.nodeType === 3 && actualNode.nodeValue.trim() | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* Check that the element has visible content | ||
* in the form of either text, an aria-label or visual content such as image | ||
* | ||
* @param {Object} virtual DOM node | ||
* @return boolean | ||
*/ | ||
dom.hasContent = function hasContent(elm) { | ||
if ( | ||
elm.actualNode.textContent.trim() || | ||
dom.hasContent = function hasContent (elm) { | ||
/* global console */ | ||
console.log( | ||
elm.actualNode, | ||
hasChildTextNodes(elm), | ||
dom.isVisualContent(elm.actualNode), | ||
aria.label(elm) | ||
) { | ||
return true; | ||
} | ||
|
||
const contentElms = axe.utils.querySelectorAll(elm, '*'); | ||
for (let i = 0; i < contentElms.length; i++) { | ||
if ( | ||
aria.label(contentElms[i]) || | ||
dom.isVisualContent(contentElms[i].actualNode) | ||
) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
); | ||
return ( | ||
// It has text | ||
hasChildTextNodes(elm) || | ||
// It is a graphical element | ||
dom.isVisualContent(elm.actualNode) || | ||
// It has an ARIA label | ||
!!aria.label(elm) || | ||
// or one of it's descendants does | ||
elm.children.some(child => ( | ||
child.actualNode.nodeType === 1 && dom.hasContent(child) | ||
)) | ||
); | ||
}; |
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
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