From aac2dcfc4cf6ddcef93933c75d3eab984f149a18 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Thu, 28 Mar 2024 11:37:07 +0300 Subject: [PATCH] fix(a11y): fixed issue with not working "enter" navigation on arrows fixes #7423 --- src/modules/a11y/a11y.mjs | 38 +++++++++++++++------------ src/modules/navigation/navigation.mjs | 4 ++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/modules/a11y/a11y.mjs b/src/modules/a11y/a11y.mjs index d663f37fe..cf5e611f5 100644 --- a/src/modules/a11y/a11y.mjs +++ b/src/modules/a11y/a11y.mjs @@ -109,24 +109,28 @@ export default function A11y({ swiper, extendParams, on }) { ) { if (!e.target.matches(classesToSelector(swiper.params.pagination.bulletClass))) return; } - if (swiper.navigation && swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl) { - if (!(swiper.isEnd && !swiper.params.loop)) { - swiper.slideNext(); - } - if (swiper.isEnd) { - notify(params.lastSlideMessage); - } else { - notify(params.nextSlideMessage); - } - } - if (swiper.navigation && swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl) { - if (!(swiper.isBeginning && !swiper.params.loop)) { - swiper.slidePrev(); + if (swiper.navigation && swiper.navigation.prevEl && swiper.navigation.nextEl) { + const prevEls = makeElementsArray(swiper.navigation.prevEl); + const nextEls = makeElementsArray(swiper.navigation.nextEl); + if (nextEls.includes(targetEl)) { + if (!(swiper.isEnd && !swiper.params.loop)) { + swiper.slideNext(); + } + if (swiper.isEnd) { + notify(params.lastSlideMessage); + } else { + notify(params.nextSlideMessage); + } } - if (swiper.isBeginning) { - notify(params.firstSlideMessage); - } else { - notify(params.prevSlideMessage); + if (prevEls.includes(targetEl)) { + if (!(swiper.isBeginning && !swiper.params.loop)) { + swiper.slidePrev(); + } + if (swiper.isBeginning) { + notify(params.firstSlideMessage); + } else { + notify(params.prevSlideMessage); + } } } diff --git a/src/modules/navigation/navigation.mjs b/src/modules/navigation/navigation.mjs index 826eb93ac..f36d57ecd 100644 --- a/src/modules/navigation/navigation.mjs +++ b/src/modules/navigation/navigation.mjs @@ -35,6 +35,8 @@ export default function Navigation({ swiper, extendParams, on, emit }) { swiper.el.querySelectorAll(el).length === 1 ) { res = swiper.el.querySelector(el); + } else if (res.length === 1) { + res = res[0]; } } if (el && !res) return el; @@ -95,11 +97,11 @@ export default function Navigation({ swiper, extendParams, on, emit }) { let nextEl = getEl(params.nextEl); let prevEl = getEl(params.prevEl); - Object.assign(swiper.navigation, { nextEl, prevEl, }); + return; nextEl = makeElementsArray(nextEl); prevEl = makeElementsArray(prevEl);