-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add shadow DOM to duplicate-img-label check (#443)
* feat: Add shadow DOM to duplicate-img-label check * fix: Use tabs
- Loading branch information
1 parent
9ddfc0f
commit 2c0b075
Showing
3 changed files
with
58 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
var imgs = node.querySelectorAll('img'); | ||
var text = axe.commons.text.visible(virtualNode, true).toLowerCase(); | ||
|
||
const text = axe.commons.text.visible(virtualNode, true).toLowerCase(); | ||
if (text === '') { | ||
return false; | ||
} | ||
|
||
for (var i = 0, len = imgs.length; i < len; i++) { | ||
var img = imgs[i]; | ||
var imgAlt = axe.commons.text.accessibleText(img).toLowerCase(); | ||
if (imgAlt === text && | ||
img.getAttribute('role') !== 'presentation' && | ||
axe.commons.dom.isVisible(img)) { | ||
return true; | ||
} | ||
} | ||
// Get all visible images in the composed tree of the current node | ||
const images = axe.utils.querySelectorAll(virtualNode, 'img') | ||
// Ignore hidden or role=none/presentation images | ||
.filter(({ actualNode }) => (axe.commons.dom.isVisible(actualNode) && | ||
!['none', 'presentation'].includes(actualNode.getAttribute('role')) | ||
)); | ||
|
||
return false; | ||
// See if any of the images duplicate the node's text | ||
return images.some(img => | ||
text === axe.commons.text.accessibleText(img).toLowerCase() | ||
); |
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