Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7761: Fixed elementIsChildOf returning false for nested web components #7762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"element": "npm run build && concurrently --kill-others \"vite ./playground/element\" \"npm run watch\" ",
"react": "npm run build && concurrently --kill-others \"vite ./playground/react\" \"npm run watch\"",
"vue": "npm run build && concurrently --kill-others \"vite ./playground/vue\" \"npm run watch\"",
"prettier": "prettier \"**/*.+(js|json|scss|css|less|ts|jsx)\"",
"prettier": "prettier \"**/*.+(js|json|scss|css|less|ts|jsx|mjs)\"",
"format": "npm run prettier -- --write",
"check-format": "npm run prettier -- --list-different",
"lint": "eslint --ext .js,.jsx .",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/a11y/a11y.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function A11y({ swiper, extendParams, on }) {
itemRoleDescriptionMessage: null,
slideRole: 'group',
id: null,
scrollOnFocus: true
scrollOnFocus: true,
},
});

Expand Down
18 changes: 13 additions & 5 deletions src/shared/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,20 @@ function elementChildren(element, selector = '') {
return children.filter((el) => el.matches(selector));
}
function elementIsChildOf(el, parent) {
const isChild = parent.contains(el);
if (!isChild && parent instanceof HTMLSlotElement) {
const children = [...parent.assignedElements()];
return children.includes(el);
// Breadth-first search through all parent's children and assigned elements
const elementsQueue = [parent];
while (elementsQueue.length > 0) {
const elementToCheck = elementsQueue.shift();
if (el === elementToCheck) {
return true;
}
elementsQueue.push(
...elementToCheck.children,
...(elementToCheck.shadowRoot?.children ?? []),
...(elementToCheck.assignedElements?.() ?? []),
);
}
return isChild;
return false;
}
function showWarning(text) {
try {
Expand Down
10 changes: 3 additions & 7 deletions src/vue/get-children.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ function getChildren(originalSlots = {}, slidesRef, oldSlidesRef) {
if (isFragment && vnode.children) {
getSlidesFromElements(vnode.children, slotName);
} else if (
(
vnode.type &&
(vnode.type.name === 'SwiperSlide' || vnode.type.name === 'AsyncComponentWrapper')
) ||
(
vnode.componentOptions && (vnode.componentOptions.tag === 'SwiperSlide')
)
(vnode.type &&
(vnode.type.name === 'SwiperSlide' || vnode.type.name === 'AsyncComponentWrapper')) ||
(vnode.componentOptions && vnode.componentOptions.tag === 'SwiperSlide')
) {
slides.push(vnode);
} else if (slots[slotName]) {
Expand Down
Loading