Skip to content

Commit

Permalink
fix(a11y): count aria-label without duplicated item in loop option
Browse files Browse the repository at this point in the history
fixes #4782
fixes #4781
  • Loading branch information
nolimits4web committed Jul 22, 2021
1 parent 07b8dc3 commit 4bd7461
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/a11y/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 4bd7461

Please sign in to comment.