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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for initial position other than 0 in useSlider #8

Closed
rockwotj opened this issue Jul 6, 2020 · 4 comments 路 Fixed by #11
Closed

Allow for initial position other than 0 in useSlider #8

rockwotj opened this issue Jul 6, 2020 · 4 comments 路 Fixed by #11
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@rockwotj
Copy link

rockwotj commented Jul 6, 2020

馃殌 Feature Proposal

Allow for useSlider hook to specify an initial position and update the slide programatically.

Motivation

I'm building a lightbox with pinch to zoom and I want to use this library but need to open a photo at any position and also need to update the position programatically.

Example

const [zooming, currentSlide, changeSlide, bind, x, onScale] = useSlider({                                                            
  numSlides: previews.length,                                                                                            
  initialSlide: initialIndex,                                                                                 
})
useKey('ArrowRight', () => changeSlide(1), [changeSlide]);
useKey('ArrowLeft', () => changeSlide(-1), [changeSlide]);
@rockwotj rockwotj added the enhancement New feature or request label Jul 6, 2020
@skozer
Copy link
Owner

skozer commented Jul 13, 2020

Great suggestion @rockwotj!

From an API perspective, I think the changeSlide function should accept either the requested slide index, or a nested function with the current slide index as an argument.

e.g.

changeSlide(3) // go to slide #4
changeSlide((currentSlide) => currentSlide + 1)) // go to slide #5

What do you think?

@skozer skozer added the good first issue Good for newcomers label Jul 13, 2020
@rockwotj
Copy link
Author

Sounds good. I'll try and throw together a PR at some point.

@skozer
Copy link
Owner

skozer commented Jul 19, 2020

@rockwotj I've split the changeSlide feature into another issue (#13) as @muhraff is working on a PR for initialSlide.

Will hopefully get this one merged in soon!

@skozer
Copy link
Owner

skozer commented Jul 27, 2020

Released in 1.4.0

@skozer skozer closed this as completed Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants