Add hasSlot utility

This commit is contained in:
Cory LaViska
2020-07-22 16:02:32 -04:00
parent 8177ce2a4a
commit 905152a412

View File

@@ -35,3 +35,10 @@ export function getTextContent(slot: HTMLSlotElement): string {
return text;
}
//
// Determines whether a slot with the given name exists in an element.
//
export function hasSlot(el: HTMLElement, name: string) {
return [...el.querySelectorAll('[slot]')].filter((slottedEl: HTMLSlotElement) => slottedEl.slot === name).length > 0;
}