Embla-carousel: 'is-selected' class not properly being toggled when 'slidesToScroll' is set to > 1

Created on 12 Sep 2020  路  4Comments  路  Source: davidcetinkaya/embla-carousel

Hello,

When using slidesToScroll: 1 the is-selected class correctly gets toggled when changing slides. This can be observed by inspecting the elements on the default codesandbox example: https://codesandbox.io/s/embla-carousel-default-vanilla-gqh0n

However when setting slidesToScroll to anything above 1, the class only gets properly toggled on the very first (1-2) picture(s) of the first slide, the rest of the pictures get is-selected added to them, but it doesn't get removed. This can be observed in the "Slides To Scroll" codesandbox example: https://codesandbox.io/s/embla-carousel-slidestoscroll-vanilla-dposi

Thank you.

bug good first issue resolved

Most helpful comment

Hello @davidcetinkaya

Thank you very much for taking the time to explain the issue and process, it helps a lot!

The fix works great, I've done all the different use-cases that I could think of and it is working as intended.

Nice work :)

All 4 comments

Hello @huttameps,

Thank you for this issue. I can confirm that it is a bug and I'm on it. I'll release a fix for this as soon as possible and will let you know when I have something.

Best,
David

Hello @huttameps,

Version 4.0.3 includes a fix for this issue. So here's some information about when slides are considered to be selected:

  • The logic for selected slides is based on what slides are in view at the target destination.
  • This logic is actually totally separated from the slidesToScroll option.
  • The issue was that when Embla was checking for slides in view, it went through the merged slidesToScroll array rather than using the raw array containing all the separate slides. This was causing the strange behavior.
  • Note that you can control the in view threshold for the slides with the inViewThreshold option. Read more about it on the documentation page.

I would very much appreciate if you could try it out and let me know if it's working as intended.

Thanks in advance,
David

Hello @davidcetinkaya

Thank you very much for taking the time to explain the issue and process, it helps a lot!

The fix works great, I've done all the different use-cases that I could think of and it is working as intended.

Nice work :)

Thanks a lot for taking the time to test the fix @huttameps. I鈥檓 glad to hear that it鈥檚 working as expected 馃憤馃徎.

I鈥檓 closing this issue for now. Enjoy!

Best,
David

Was this page helpful?
0 / 5 - 0 ratings