YIZHUANG / react-multi-carousel

A lightweight production-ready Carousel that rocks supports multiple items and server-side rendering with no dependency. Bundle size 2kb.
MIT License
1.25k stars 286 forks source link

New Feature: goToSlide ignore animation option #323

Open rebecca-millerr opened 2 years ago

rebecca-millerr commented 2 years ago

Prerequisite

Before you submit a feature request or report a bug to be fixed, make sure you have stared this repository. A donation is also welcomed

Describe the bug It would be great if goToSlide had an optional argument that could cause the carousel to bypass/ignore the animation. For example, if you wanted to instantaneously skip to a slide on rerender.

To Reproduce Steps to reproduce the behavior (there are definitely other ways to see this but this is how I found it):

  1. Create a carousel with some items (mine had 5 items total, 1 visible at a time)
  2. Create a ref to the carousel and manage it in a parent component
  3. From the parent component, using a useEffect to determine whenever the ref updates, use carouselRef?.goToSlide(someNumber)
  4. See how it animates - I want this to be instantaneous

Expected behavior I wanted the transition to the target slide to be instantaneous. Note: I cannot just change transitionDuration to 0 because I want the animations when the arrows are clicked to work regularly.

Screenshots N/A

Additional context I believe the issue could be fixed with an optional parameter in the goToSlide function, perhaps skipAnimation?: boolean and then this.animationAllowed will only become true if this is false or undefined. This is only a couple lines of code!

Reproduction N/A