Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/utils/slot-mutation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import { raf } from '@utils/helpers';
* This is not needed for components using native slots in the Shadow DOM.
* @internal
* @param el The host element to observe
* @param slotName mutationCallback will fire when nodes on this slot change
* @param slotName mutationCallback will fire when nodes on these slot(s) change
* @param mutationCallback The callback to fire whenever the slotted content changes
*/
export const createSlotMutationController = (
el: HTMLElement,
slotName: string,
slotName: string | string[],
mutationCallback: () => void
): SlotMutationController => {
let hostMutationObserver: MutationObserver | undefined;
let slottedContentMutationObserver: MutationObserver | undefined;

if (win !== undefined && 'MutationObserver' in win) {
const slots = Array.isArray(slotName) ? slotName : [slotName];

hostMutationObserver = new MutationObserver((entries) => {
for (const entry of entries) {
for (const node of entry.addedNodes) {
/**
* Check to see if the added node
* is our slotted content.
*/
if (node.nodeType === Node.ELEMENT_NODE && (node as HTMLElement).slot === slotName) {
if (node.nodeType === Node.ELEMENT_NODE && slots.includes((node as HTMLElement).slot)) {
/**
* If so, we want to watch the slotted
* content itself for changes. This lets us
Expand Down