Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add scrollBehavior prop #18

Closed
olivier-drieux opened this issue Aug 25, 2023 · 2 comments · Fixed by #23
Closed

Add scrollBehavior prop #18

olivier-drieux opened this issue Aug 25, 2023 · 2 comments · Fixed by #23

Comments

@olivier-drieux
Copy link

By default, the scroll behavior in the hook is 'smooth' (see use-snap-carousel.tsx:169).
Capture d’écran 2023-08-25 à 10 11 28
There is a known bug on chromium based browsers with smooth scroll behavior (ex: https://bugs.chromium.org/p/chromium/issues/detail?id=1299237).
I would like to be able to change the scroll behavior when using the useSnapCarousel hook.
I can do a PR if you want to.

@richardscarrott
Copy link
Owner

richardscarrott commented Aug 25, 2023

Can't say I've run into that issue myself but happy to accept a PR.

I think it'd make most sense to pass it into goTo, next and prev independently as I know a few use cases where you'd want to sometimes animate and other times jump instantly.

Something like this

type SnapCarouselGoToOptions = {
  readonly behavior: ScrollBehavior;
};

// ...

const { scrollRef, prev, next, goTo } = useSnapCarousel();
return (
  <div style={styles.root}>
    <button onClick={() => goTo(0, { behavior: 'auto' })}>start</button>
    <button onClick={() => prev({ behavior: 'auto' })}>prev</button>
    <button onClick={() => next({ behavior: 'auto' })}>next</button>

    <ul style={styles.scroll} ref={scrollRef}>
      {items.map((item, i) =>
        renderItem({
          item,
          isSnapPoint: snapPointIndexes.has(i)
        })
      )}
    </ul>
  </div>
);

@richardscarrott
Copy link
Owner

Released in 0.4.0, thanks for the contribution @pantajoe 🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants