Skip to content

Commit

Permalink
feat(custom-elements): ✨ obtain children of shadow node for custom el…
Browse files Browse the repository at this point in the history
…ements

Inspired by tsayen/dom-to-image#370

If element has `shadowRoot` property it is custom
(and the shadow node is open) so fetch it's children.

Closes #128
  • Loading branch information
ShaMan123 committed May 14, 2021
1 parent ffc70d1 commit 021f124
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cloneNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ async function cloneChildren(
clonedNode: HTMLElement,
filter?: Function,
): Promise<HTMLElement> {
const children = toArray<HTMLElement>(nativeNode.childNodes)
const children = toArray<HTMLElement>(
(nativeNode.shadowRoot ?? nativeNode).childNodes,
)
if (children.length === 0) {
return Promise.resolve(clonedNode)
}
Expand Down

0 comments on commit 021f124

Please sign in to comment.