Skip to content

Commit d12f4e2

Browse files
Marshal27Marshal Thompson
andauthored
fix: 🐛 ternary to convert slot assignedNodes to array (bubkoo#168)
Co-authored-by: Marshal Thompson <marshal.thompson@cpsi.com>
1 parent 90eb95d commit d12f4e2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/cloneNode.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ async function cloneChildren<T extends HTMLElement>(
3333
clonedNode: T,
3434
options: Options,
3535
): Promise<T> {
36-
const children = toArray<T>((nativeNode.shadowRoot ?? nativeNode).childNodes)
36+
const children =
37+
isSlotElement(nativeNode) && nativeNode.assignedNodes
38+
? toArray<T>(nativeNode.assignedNodes())
39+
: toArray<T>((nativeNode.shadowRoot ?? nativeNode).childNodes)
3740

3841
if (children.length === 0) {
3942
return Promise.resolve(clonedNode)
@@ -114,3 +117,6 @@ export async function cloneNode<T extends HTMLElement>(
114117
.then((clonedNode) => cloneChildren(nativeNode, clonedNode, options))
115118
.then((clonedNode) => decorate(nativeNode, clonedNode))
116119
}
120+
121+
const isSlotElement = (node: Element): node is HTMLSlotElement =>
122+
node.tagName === 'SLOT'

0 commit comments

Comments
 (0)