Skip to content

Commit eec4594

Browse files
7761: Fixed elementIsChildOf returning false for nested web components; added .mjs files to prettier job
1 parent 40a705e commit eec4594

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"element": "npm run build && concurrently --kill-others \"vite ./playground/element\" \"npm run watch\" ",
1414
"react": "npm run build && concurrently --kill-others \"vite ./playground/react\" \"npm run watch\"",
1515
"vue": "npm run build && concurrently --kill-others \"vite ./playground/vue\" \"npm run watch\"",
16-
"prettier": "prettier \"**/*.+(js|json|scss|css|less|ts|jsx)\"",
16+
"prettier": "prettier \"**/*.+(js|json|scss|css|less|ts|jsx|mjs)\"",
1717
"format": "npm run prettier -- --write",
1818
"check-format": "npm run prettier -- --list-different",
1919
"lint": "eslint --ext .js,.jsx .",

src/modules/a11y/a11y.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function A11y({ swiper, extendParams, on }) {
1919
itemRoleDescriptionMessage: null,
2020
slideRole: 'group',
2121
id: null,
22-
scrollOnFocus: true
22+
scrollOnFocus: true,
2323
},
2424
});
2525

src/shared/utils.mjs

+13-5
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,20 @@ function elementChildren(element, selector = '') {
214214
return children.filter((el) => el.matches(selector));
215215
}
216216
function elementIsChildOf(el, parent) {
217-
const isChild = parent.contains(el);
218-
if (!isChild && parent instanceof HTMLSlotElement) {
219-
const children = [...parent.assignedElements()];
220-
return children.includes(el);
217+
// Breadth-first search through all parent's children and assigned elements
218+
const elementsQueue = [parent];
219+
while (elementsQueue.length > 0) {
220+
const elementToCheck = elementsQueue.shift();
221+
if (el === elementToCheck) {
222+
return true;
223+
}
224+
elementsQueue.push(
225+
...elementToCheck.children,
226+
...(elementToCheck.shadowRoot?.children ?? []),
227+
...(elementToCheck.assignedElements?.() ?? []),
228+
);
221229
}
222-
return isChild;
230+
return false;
223231
}
224232
function showWarning(text) {
225233
try {

src/vue/get-children.mjs

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ function getChildren(originalSlots = {}, slidesRef, oldSlidesRef) {
1818
if (isFragment && vnode.children) {
1919
getSlidesFromElements(vnode.children, slotName);
2020
} else if (
21-
(
22-
vnode.type &&
23-
(vnode.type.name === 'SwiperSlide' || vnode.type.name === 'AsyncComponentWrapper')
24-
) ||
25-
(
26-
vnode.componentOptions && (vnode.componentOptions.tag === 'SwiperSlide')
27-
)
21+
(vnode.type &&
22+
(vnode.type.name === 'SwiperSlide' || vnode.type.name === 'AsyncComponentWrapper')) ||
23+
(vnode.componentOptions && vnode.componentOptions.tag === 'SwiperSlide')
2824
) {
2925
slides.push(vnode);
3026
} else if (slots[slotName]) {

0 commit comments

Comments
 (0)