Skip to content

Commit 7ec975c

Browse files
committed
fix(core): fix element child detection
fixes #7636
1 parent 845a206 commit 7ec975c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/shared/utils.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,22 @@ function findElementsInElements(elements = [], selector = '') {
204204
}
205205
function elementChildren(element, selector = '') {
206206
const children = [...element.children];
207-
if(element instanceof HTMLSlotElement) {
208-
children.push(...element.assignedElements())
207+
if (element instanceof HTMLSlotElement) {
208+
children.push(...element.assignedElements());
209209
}
210210

211-
if(!selector) {
211+
if (!selector) {
212212
return children;
213213
}
214214
return children.filter((el) => el.matches(selector));
215215
}
216216
function elementIsChildOf(el, parent) {
217-
const children = elementChildren(parent);
218-
return children.includes(el);
217+
const isChild = parent.contains(el);
218+
if (!isChild && parent instanceof HTMLSlotElement) {
219+
const children = [...element.assignedElements()];
220+
return children.includes(el);
221+
}
222+
return isChild;
219223
}
220224
function showWarning(text) {
221225
try {

0 commit comments

Comments
 (0)