Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Expose setSlide function #100

Closed
hyochan opened this issue Apr 9, 2020 · 8 comments · Fixed by #101
Closed

Expose setSlide function #100

hyochan opened this issue Apr 9, 2020 · 8 comments · Fixed by #101
Labels
bug Something isn't working released

Comments

@hyochan
Copy link

hyochan commented Apr 9, 2020

Could you expose setSlide method in here?

I'd like to manually slide even without dragging by clicking on the element outside the div.

Hope this could be applied soon or I'd like to fork this repo and use for myself :)

Thanks for all the work in advance.

@hyochan hyochan changed the title Expose setSlide method Expose setSlide function Apr 9, 2020
@Tobi-mmt
Copy link
Member

Tobi-mmt commented Apr 9, 2020

Hey @hyochan, thanks for your input.

We allready thought about this and you can set the active slide with the activeIndex prop

For example

const foo = () => {
  const [sliderIndex, setSliderIndex] = useState(0)
  return (
    <button onClick={() => setSliderIndex(2)}>Move to third slide</button>
    <Slider activeIndex={sliderIndex}>
      <MySlide />
      <MySlide />
      <MySlide />
    </Slider>
)}

@hyochan
Copy link
Author

hyochan commented Apr 9, 2020

@Tobi-mmt Thanks for the feedback. I"ve already tried that but that only works at the initial state. When you swipe children around and call setSliderIndex it won't do anything.

@mstruebing
Copy link
Contributor

@hyochan
Copy link
Author

hyochan commented Apr 10, 2020

Sorry that I've not made it clear. To be specific, I want to tell you what I'm trying to build today.
I want to make my calendar carousel just like I did in flutter in flutter_calendar_carousel.

If I use below code with const [activeIndex, setActiveIndex] = useState<number>(0);, it won't do anything.
image

vPjzdT54pA

Also, it'd be good if we can set index sometimes without animation and sometimes with animation.

@hyochan
Copy link
Author

hyochan commented Apr 10, 2020

@mstruebing Would above make you clear now? Please tell me if anything isn't clear! Thanks.

@mstruebing mstruebing added the bug Something isn't working label Apr 10, 2020
@mstruebing
Copy link
Contributor

Ah I can reproduce what you mean. It seems that this is indeed not working and it is a bug in my opinion so we should fix it.
Thank you for making it clear, we will try to provide a proper patch soonish.

@mstruebing
Copy link
Contributor

I added the ability to add a property setSlideCustom which needs a function with the following signature: (slide: number) => number - because the bug I've thought was totally correct react behaviour.
I hope that will help you

mstruebing added a commit that referenced this issue May 14, 2020
* test: Add test for activeIndex manipulating onSlideChange

* feat: Add optionally custom `setSlide` function

closes #100

* docs: Add `setSlideCustom` to changelog

* docs: Add `setSlideCustom` to readme

* Update README.md

Co-authored-by: Tobias <tobi.l@posteo.at>

Co-authored-by: Tobias <tobi.l@posteo.at>
github-actions bot pushed a commit that referenced this issue Jun 8, 2020
# [1.2.0](v1.1.1...v1.2.0) (2020-06-08)

### Features

* Add optionally custom `setSlide` function ([#101](#101)) ([b3889e4](b3889e4)), closes [#100](#100)
@github-actions
Copy link

github-actions bot commented Jun 8, 2020

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants