From 4bd7461f4c7ba0ca097a8d5a77881a547b0545e7 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Thu, 22 Jul 2021 12:03:43 +0300 Subject: [PATCH] fix(a11y): count aria-label without duplicated item in loop option fixes #4782 fixes #4781 --- src/components/a11y/a11y.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/a11y/a11y.js b/src/components/a11y/a11y.js index abd5bb995..e41406cd1 100644 --- a/src/components/a11y/a11y.js +++ b/src/components/a11y/a11y.js @@ -160,11 +160,19 @@ const A11y = { swiper.a11y.addElRoleDescription($(swiper.slides), params.itemRoleDescriptionMessage); } swiper.a11y.addElRole($(swiper.slides), params.slideRole); - swiper.slides.each((slideEl) => { + + const slidesLength = swiper.params.loop + ? swiper.slides.filter((el) => !el.classList.contains(swiper.params.slideDuplicateClass)) + .length + : swiper.slides.length; + swiper.slides.each((slideEl, index) => { const $slideEl = $(slideEl); + const slideIndex = swiper.params.loop + ? parseInt($slideEl.attr('data-swiper-slide-index'), 10) + : index; const ariaLabelMessage = params.slideLabelMessage - .replace(/\{\{index\}\}/, $slideEl.index() + 1) - .replace(/\{\{slidesLength\}\}/, swiper.slides.length); + .replace(/\{\{index\}\}/, slideIndex + 1) + .replace(/\{\{slidesLength\}\}/, slidesLength); swiper.a11y.addElLabel($slideEl, ariaLabelMessage); });