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

slickGoTo has the wrong animation direction when moving from the first to last index #1869

Open
juansalvatore opened this issue Aug 12, 2020 · 3 comments · May be fixed by #2056
Open

slickGoTo has the wrong animation direction when moving from the first to last index #1869

juansalvatore opened this issue Aug 12, 2020 · 3 comments · May be fixed by #2056

Comments

@juansalvatore
Copy link

juansalvatore commented Aug 12, 2020

"slickGoTo" has the wrong animation direction when moving from the first to last index and from last to first

Codesandbox example: https://codesandbox.io/s/slickgoto-issue-dhf76
Steps to reproduce:

  • Go to https://dhf76.csb.app/
  • Click on 1, 2, 3 and you'll see that the animation works ok
  • Now try clicking on 1 and then 10
    Current result: The animation moves to the right from 1 all over to 10.
    Expected result: The animation moves to the left just 1 slide.

This happens either way if infinite is set to true in center mode

@juansalvatore
Copy link
Author

A temporary work around I was able to find was this:

useEffect(() => {
      if (!carouselRef.current?.slickGoTo) return;
      const isBorderCase =
        (selectedVariationIndex > previousSelectedVariation.current &&
          selectedVariationIndex - previousSelectedVariation.current > selectedAssetVariationsLength / 2) ||
        (previousSelectedVariation.current > selectedVariationIndex &&
          previousSelectedVariation.current - selectedVariationIndex > selectedAssetVariationsLength / 2);

      if (isBorderCase) {
        const isForward = previousSelectedVariation.current - selectedVariationIndex > 0;

        if (isForward) {
          const nextIndex =
            (previousSelectedVariation.current - selectedVariationIndex - selectedAssetVariationsLength) * -1 +
            selectedAssetVariationsLength;
          carouselRef.current?.slickGoTo(nextIndex);

          previousSelectedVariation.current = selectedVariationIndex;
          return;
        }
        const previousIndex = selectedVariationIndex - selectedAssetVariationsLength;
        carouselRef.current?.slickGoTo(previousIndex);

        previousSelectedVariation.current = selectedVariationIndex;
        return;
      }

      carouselRef.current?.slickGoTo(selectedVariationIndex);
      previousSelectedVariation.current = selectedVariationIndex;
    }, [selectedAssetVariationsLength, selectedVariationIndex]);

It still has the issue that if the user clicks fast enough the animation has the same bug shared in the issue

@mrviniciux
Copy link

I'm taking a look on this

@mrviniciux mrviniciux linked a pull request Jul 8, 2021 that will close this issue
@mrviniciux
Copy link

Hope that works, this is good to review/QA @akiran @juansalvatore

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

Successfully merging a pull request may close this issue.

3 participants