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

Support infinite carousels #27

Merged
merged 1 commit into from
Sep 3, 2024
Merged

Support infinite carousels #27

merged 1 commit into from
Sep 3, 2024

Conversation

richardscarrott
Copy link
Owner

@richardscarrott richardscarrott commented Sep 3, 2024

I finally came across a requirement for infinite carousels so I've made a minor tweak to react snap carousel to better support them.

The tweak isn't directly related to infinite carousels, but it helps with the implementation I'm using -- an example of which can be found in this PR.

Long story short, you can now add a data attribute <li data-should-snap="true" /> to an item and it will become a snap point -- that is to say it will be used as the first item of a new page of items.

Why is it a DOM attribute and not a React prop?

Fundamentally React Snap Carousel computes "pages" based on the DOM layout which isn't modelled in React code, so it seems both appropriate and pragmatic to offer up a DOM-based API to tell React Snap Carousel where to start a page from -- it's conceptually the same as adding some CSS to an item, causing the page groupings to change.

@richardscarrott richardscarrott merged commit d02829a into main Sep 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant