The Wayback Machine - https://web.archive.org/web/20201120212846/https://github.com/leandrowd/react-responsive-carousel/issues/327
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

OnClickItem does not trigger onChange the first time it's clicked #327

Open
vasupol11 opened this issue Apr 15, 2019 · 1 comment
Open

OnClickItem does not trigger onChange the first time it's clicked #327

vasupol11 opened this issue Apr 15, 2019 · 1 comment

Comments

@vasupol11
Copy link

@vasupol11 vasupol11 commented Apr 15, 2019

I am using the selectedItem prop to control my slide position. It works fine, but when I am trying to override onClickItem it has to be clicked on twice to execute the function I give it. In my case, I want any slide clicked on to return to the first slide (just for testing).

Currently:
first click: the position moves to the clicked slide
second click: the position is 0

What I expect:
first click: the position is 0

constructor(props){
        super(props)
        this.settings = {
            onChange: this.updateCurrentSlide,
            onClickItem: this.clickOnItem
        }

        this.state = {
            currentSlide: 1
        }
    }

    clickOnItem = (clickedSlide) => {
        this.setState({currentSlide: 0});
    }

   render(){
           <Carousel {...this.settings} selectedItem={this.state.currentSlide}>{this.props.children} 
     </Carousel>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.