From 7ec975c8550bfebacc7ecd032dc540e720f45175 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Wed, 24 Jul 2024 09:47:45 +0300 Subject: [PATCH] fix(core): fix element child detection fixes #7636 --- src/shared/utils.mjs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shared/utils.mjs b/src/shared/utils.mjs index ed3423ca7..b0a69e288 100644 --- a/src/shared/utils.mjs +++ b/src/shared/utils.mjs @@ -204,18 +204,22 @@ function findElementsInElements(elements = [], selector = '') { } function elementChildren(element, selector = '') { const children = [...element.children]; - if(element instanceof HTMLSlotElement) { - children.push(...element.assignedElements()) + if (element instanceof HTMLSlotElement) { + children.push(...element.assignedElements()); } - if(!selector) { + if (!selector) { return children; } return children.filter((el) => el.matches(selector)); } function elementIsChildOf(el, parent) { - const children = elementChildren(parent); - return children.includes(el); + const isChild = parent.contains(el); + if (!isChild && parent instanceof HTMLSlotElement) { + const children = [...element.assignedElements()]; + return children.includes(el); + } + return isChild; } function showWarning(text) { try {