Skip to content

Commit 2ba035a

Browse files
author
kai
committed
Fix node component slotting
1 parent 14442ab commit 2ba035a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/NodeComponent.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,13 @@ export abstract class NodeComponent<T extends Node> {
7676

7777
/**
7878
* Render this component in the place of a `<slot name="…"></slot>`.
79-
* If multiple slots with the same name are found, they will all be used.
8079
* @param slot The slot name
8180
* @param [parent] The parent element within to search for slots. Defaults to `document`
8281
*/
8382
public slot(slot: string, parent: ParentNode = document) {
84-
const slotNodes = parent.querySelectorAll(`slot[name="${slot}"]`);
85-
for (const slotNode of slotNodes)
86-
slotNode.replaceWith(this.node);
83+
const slotNode = parent.querySelector(`slot[name="${slot}"]`);
84+
if (slotNode == null) throw new DOMException(`NodeComponent.slot: Could not find slot ${slot}`);
85+
slotNode.replaceWith(this.node);
8786
return this;
8887
}
8988
}

0 commit comments

Comments
 (0)