-
Notifications
You must be signed in to change notification settings - Fork 776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(duplicate-id): Add shadow DOM support #452
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,21 +1,17 @@ | ||
const id = node.getAttribute('id').trim(); | ||
// Since empty ID's are not meaningful and are ignored by Edge, we'll | ||
// let those pass. | ||
if (!node.getAttribute('id').trim()) { | ||
if (!id) { | ||
return true; | ||
} | ||
const root = axe.commons.dom.getRootNode(node); | ||
const matchingNodes = Array.from(root.querySelectorAll( | ||
`[id="${ axe.commons.utils.escapeSelector(id) }"]` | ||
)).filter(foundNode => foundNode !== node); | ||
|
||
const id = axe.commons.utils.escapeSelector(node.getAttribute('id')); | ||
var matchingNodes = document.querySelectorAll(`[id="${id}"]`); | ||
var related = []; | ||
|
||
for (var i = 0; i < matchingNodes.length; i++) { | ||
if (matchingNodes[i] !== node) { | ||
related.push(matchingNodes[i]); | ||
} | ||
} | ||
if (related.length) { | ||
this.relatedNodes(related); | ||
if (matchingNodes.length) { | ||
this.relatedNodes(matchingNodes); | ||
} | ||
this.data(node.getAttribute('id')); | ||
this.data(id); | ||
|
||
return (matchingNodes.length <= 1); | ||
return (matchingNodes.length === 0); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of this looks like it is being ignored–there are 3 ids of
target
, and the result doesn't seem to include anything about the one inside the Shadow DOM. To me it seems like it should be ignored, but I wasn't sure how the<slot>
came into it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDs are scoped to their respective root. In this example, the
div
andp
both havedocument
as the root, and sop
is the duplicate in this example. But becausespan
is in the shadow tree, it can have an ID that already exists in the document (or even in another shadow tree).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the description of the test is just confusing?
it should not ignore slotted elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the description of the test because it describes what is actually happening i.e. that the slotted content (light DOM) is being compared with the light DOM and not the shadow DOM it is slotted into. You could slightly clarify it by saying