From af0519c22513ec4a7bad2c80896d421fe07012f8 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Wed, 30 Aug 2023 12:04:38 +0300 Subject: [PATCH] fix(core): fix `slideToClickedSlide` when using Element slide slots fixes #6958 --- src/core/events/onTouchEnd.mjs | 2 +- src/core/update/updateClickedSlide.mjs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/events/onTouchEnd.mjs b/src/core/events/onTouchEnd.mjs index 4581d0193..4a781977a 100644 --- a/src/core/events/onTouchEnd.mjs +++ b/src/core/events/onTouchEnd.mjs @@ -51,7 +51,7 @@ export default function onTouchEnd(event) { // Tap, doubleTap, Click if (swiper.allowClick) { const pathTree = e.path || (e.composedPath && e.composedPath()); - swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target); + swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree); swiper.emit('tap click', e); if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) { swiper.emit('doubleTap doubleClick', e); diff --git a/src/core/update/updateClickedSlide.mjs b/src/core/update/updateClickedSlide.mjs index f750811ff..d854d6b6c 100644 --- a/src/core/update/updateClickedSlide.mjs +++ b/src/core/update/updateClickedSlide.mjs @@ -1,7 +1,14 @@ -export default function updateClickedSlide(e) { +export default function updateClickedSlide(el, path) { const swiper = this; const params = swiper.params; - const slide = e.closest(`.${params.slideClass}, swiper-slide`); + let slide = el.closest(`.${params.slideClass}, swiper-slide`); + if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) { + [...path.slice(path.indexOf(el) + 1, path.length)].forEach((pathEl) => { + if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) { + slide = pathEl; + } + }); + } let slideFound = false; let slideIndex;