Skip to content

Commit 38e4864

Browse files
author
Kai
authored
Remove multiple slots in slotting (#23)
2 parents 14442ab + afa9a0b commit 38e4864

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/NodeComponent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ 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.
79+
* @throws {@link !DOMException} When the slot is not found
8080
* @param slot The slot name
8181
* @param [parent] The parent element within to search for slots. Defaults to `document`
8282
*/
8383
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);
84+
const slotNode = parent.querySelector(`slot[name="${slot}"]`);
85+
if (slotNode === null) throw new DOMException(`Could not find slot "${slot}"`);
86+
slotNode.replaceWith(this.node);
8787
return this;
8888
}
8989
}

0 commit comments

Comments
 (0)