Skip to content
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

Carousel is not correctly sliding from first index to last in 'prev' direction #5319

Closed
AndrewCi opened this issue Jul 22, 2020 · 4 comments · Fixed by #5322
Closed

Carousel is not correctly sliding from first index to last in 'prev' direction #5319

AndrewCi opened this issue Jul 22, 2020 · 4 comments · Fixed by #5322

Comments

@AndrewCi
Copy link

AndrewCi commented Jul 22, 2020

When on the first slide and triggering a slide event in 'prev' direction, the carousel slides to the correct element, the last slide, but with a 'next' animation. This can, for example, be observed in the documentation here:

https://react-bootstrap.github.io/components/carousel/#example

The effect is most apparent when repeatedly sliding to the previous slide. The transition from first to last is simply off.

For comparison the expected behavior from the Bootstrap carousel:

https://getbootstrap.com/docs/4.0/components/carousel/#with-controls

Unfortunately my knowledge in this area is so limited that I can't even find the event handler responsible for the actual transition, so I don't actually know where to look for this, but maybe one of you guys know why this is happening.

I'm using v1.2.2. Here is an example (not sure if it's the same version) https://codesandbox.io/s/runtime-grass-l2cg4?file=/package.json

related to #3654

@AndrewCi
Copy link
Author

@kosmiq

@kyletsang
Copy link
Member

I can repro this in the code sandbox example, but not the RB site. Looks like the StrictMode in the code sandbox is causing multiple renders which causes the following code to recalculate the direction in the wrong way.

if (nextDirectionRef.current) {
setDirection(nextDirectionRef.current);
nextDirectionRef.current = null;
} else {
setDirection((activeIndex || 0) > renderedActiveIndex ? 'next' : 'prev');
}

@AndrewCi
Copy link
Author

I can repro this in the code sandbox example, but not the RB site. Looks like the StrictMode in the code sandbox is causing multiple renders which causes the following code to recalculate the direction in the wrong way.

if (nextDirectionRef.current) {
setDirection(nextDirectionRef.current);
nextDirectionRef.current = null;
} else {
setDirection((activeIndex || 0) > renderedActiveIndex ? 'next' : 'prev');
}

Interesting. I currently run my site wrapped within StrictMode so that might explain the source of the issue. Is there an easy way to make this component compatible with StrictMode?

@kyletsang
Copy link
Member

Unfortunately no. Might have a fix here, just testing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants