FormidableLabs / nuka-carousel

Small, fast, and accessibility-first React carousel library with an easily customizable UI and behavior to fit your brand and site.
https://commerce.nearform.com/open-source/nuka-carousel
Other
3k stars 596 forks source link

Carousel doesn't autoplay when autoplayReverse is true and slideIndex={0} #1005

Closed EngrTactics closed 1 year ago

EngrTactics commented 1 year ago

Bugs and Questions

Prerequisites

Describe Your Environment

Describe the Problem

Carousel doesn't autoplay when autoplayReverse is true and slideIndex={0}

Expected behavior:

I expect the carousels to autoplay from slide(0) to slide(n) and reverse either by starting from slide(0) again or by sliding back to slide(n-1) n=number of elements in the carousel.

Actual behavior

It works if autoplayreverse is not set to true and the slide index is not set but it sets the slide index to (n) by default

Additional Information

fritz-c commented 1 year ago

Rather than setting slideIndex to start from your first slide, how about rearranging the order of the slides themselves so your first slide appears in the slide(n-1) position? So if you have slides 1,2,3,4, you rearrange them to 2,3,4,1.

In code: If your original render logic looks like:

{slides.map(slide => /* ... render individual slides ... */)}

you could do this:

{[...slides.slice(1), slides[0]].map(slide => /* ... render individual slides ... */)}
EngrTactics commented 1 year ago

Okay! but even after that, the carousel autoplay only once.

fritz-c commented 1 year ago

Add the wrapAround prop to make it loop indefinitely.

EngrTactics commented 1 year ago

Works now! Thanks a lot!