Skip to content

Commit 5c727b0

Browse files
GeorgegriffggriffithsIDBS
authored andcommitted
fixes #7
1 parent ca141c6 commit 5c727b0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-selector-shadow-dom",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "use querySelector syntax to search for nodes inside of (nested) shadow roots",
55
"main": "src/querySelectorDeep.js",
66
"scripts": {

src/querySelectorDeep.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ function collectAllElementsDeep(selector = null, root) {
136136
}
137137
}
138138
};
139-
139+
if(root.shadowRoot) {
140+
findAllElements(root.shadowRoot.querySelectorAll('*'));
141+
}
140142
findAllElements(root.querySelectorAll('*'));
141143

142144
return selector ? allElements.filter(el => el.matches(selector)) : allElements;

test/basic.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ describe("Basic Suite", function() {
4040
expect(testComponent).toBeTruthy();
4141
});
4242

43+
it('can access direct shadow dom child of the root', function() {
44+
const rootComponent = createTestComponent(parent, {
45+
childClassName: "child-class",
46+
});
47+
const child = querySelectorDeep('.child-class', rootComponent);
48+
expect(child).toBeTruthy();
49+
});
50+
51+
4352
it('can access an element in the shadow dom', function() {
4453
createTestComponent(parent, {
4554
childTextContent: 'Child Content'

0 commit comments

Comments
 (0)