Skip to content

Wrong thumb activated when using virtual slides #7962

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

Open
5 of 6 tasks
Phaiax opened this issue Apr 18, 2025 · 0 comments
Open
5 of 6 tasks

Wrong thumb activated when using virtual slides #7962

Phaiax opened this issue Apr 18, 2025 · 0 comments

Comments

@Phaiax
Copy link

Phaiax commented Apr 18, 2025

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/p/sandbox/bug-repro-virtual-slides-thumbs-forked-287y2w

Bug description

The active slide is calculated wrongly when using virtual slides. This happens only for slides in the low digits slide indexes and depends on e.g. the values of addSlidesAfter and addSlidesBefore.

From my analysis, this is where it goes wrong (in the instance of the virtual main swiper). See comment after // >>>.

function updateActiveIndex(newActiveIndex) {

    // ... snip ...

      // Get real index
      let realIndex;
      if (swiper.virtual && params.virtual.enabled && params.loop) {
        realIndex = getVirtualRealIndex(activeIndex);
      } else if (gridEnabled) {
        const firstSlideInColumn = swiper.slides.find(slideEl => slideEl.column === activeIndex);
        let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
        if (Number.isNaN(activeSlideIndex)) {
          activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
        }
        realIndex = Math.floor(activeSlideIndex / params.grid.rows);
      } else if (swiper.slides[activeIndex]) {
// >>> activeIndex is from the virtual index, but swiper.slides[] just contains 
//         `addSlidesAfter` + 1 + `addSlidesBefore` slides. If activeIndex is quite
//         low, then it enters this branch, and retrieves a wrong index from the
//          attribute in the next line.
        const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
        if (slideIndex) {
          realIndex = parseInt(slideIndex, 10);
        } else {
          realIndex = activeIndex;
        }
      } else {
        realIndex = activeIndex;
      }

   // ... snip ...
}

These issues could have the same root cause, but I'm not sure: #7918 #7669 #7377

Expected Behavior

Thumbs are synced with the main swiper correctly.

Actual Behavior

The wrong thumb is highlighted when using the paginators while going through the slides. There are similar effects when clicking on the thumbs itself. Depending on the screen size and thumb widths, the thumb swiper scrolls to the wrong thumb.

Swiper version

11.2.6

Platform/Target and Browser Versions

Firefox, Chrome

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
@Phaiax Phaiax changed the title Wrong thumb activated when using virual slides Wrong thumb activated when using virtual slides Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant