Open wilsonc-pella opened 4 years ago
Met the same behavior on my carousel, my config:
infinite: true,
accessibility: true,
vertical: true,
focusOnSelect: true,
slidesToShow: 1,
speed: 200,
centerMode: true
centerPadding: '160px'
Same for me
I don't know if this will introduce new bug but it work for my case
The problem I think is because there is a condition where if targetIndex overflow, it will reset to index 0 i.e. Inside /utils/innerSliderUtils.js
if (centerMode && animationSlide >= slideCount) {
animationSlide = infinite ? slideCount : slideCount - 1;
finalSlide = infinite ? 0 : slideCount - 1;
}
Which should be
if (centerMode && animationSlide >= slideCount) {
animationSlide = infinite ? finalSlide : slideCount - 1;
finalSlide = infinite ? finalSlide % slideCount : slideCount - 1;
}
I am using react-slick 0.28.1 Here is how I fix it.
npm i patch-package
{
...
"scripts":{
...
"postinstall":"patch-package"
}
}
diff --git a/node_modules/react-slick/dist/react-slick.js b/node_modules/react-slick/dist/react-slick.js
index 8b9d7d3..fd1a199 100644
--- a/node_modules/react-slick/dist/react-slick.js
+++ b/node_modules/react-slick/dist/react-slick.js
@@ -2048,8 +2048,8 @@ var slideHandler = function slideHandler(spec) {
} else if (!canGoNext(spec) && animationSlide > currentSlide) {
animationSlide = finalSlide = currentSlide;
} else if (centerMode && animationSlide >= slideCount) {
- animationSlide = infinite ? slideCount : slideCount - 1;
- finalSlide = infinite ? 0 : slideCount - 1;
+ animationSlide = infinite ? finalSlide : slideCount - 1;
+ finalSlide = infinite ? finalSlide % slideCount : slideCount - 1;
} else if (animationSlide >= slideCount) {
finalSlide = animationSlide - slideCount;
if (!infinite) finalSlide = slideCount - slidesToShow;else if (slideCount % slidesToScroll !== 0) finalSlide = 0;
npm i
import Slider from 'react-slick'
to
import Slider from 'react-slick/dist/react-slick'
Issue replicated here, click on slide 8 on the left, then slide 5 on left, slide 1 ends up as the active slide.
https://codesandbox.io/s/react-slick-playground-jnn9l
config: accessibility: true, focusOnSelect: true, className: "configSlider", infinite: true, centerMode: true, slidesToShow: 1, slidesToScroll: 1, variableWidth: true,