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

the function onChangeComplete run two times #114

Open
qqstt opened this issue Mar 22, 2018 · 5 comments
Open

the function onChangeComplete run two times #114

qqstt opened this issue Mar 22, 2018 · 5 comments

Comments

@qqstt
Copy link

qqstt commented Mar 22, 2018

No description provided.

@aaaronMF
Copy link

aaaronMF commented May 24, 2018

I found that if I click the slider, without moving the slider thumb (so not changing the value), onChangeComplete will get called three times

@av-k
Copy link

av-k commented May 29, 2018

Manual fix (hack) for fix case:

import React, { Component } from 'react'
import Slider from 'react-rangeslider'

class Horizontal extends Component {
  constructor (props, context) {
    super(props, context)
    this.timer = null;
    this.state = {
      delay: props.delay || 100
      value: 10
    }
  }

  handleChangeStart = () => {
    console.log('Change event started');
  };

  handleChange = value => {
    this.setState({
      value
    });
  };

   /**
    * Here we use timer for fix
    */
  handleChangeComplete = () => {
      const {onComplete = () => {}} = this.props;
      const {value, delay} = this.state;

      clearTimeout(this.timer);
      this.timer = setTimeout(function() {
         // once
         onComplete({value});
      }, 100);
  };

  render () {
    const { value } = this.state
    return (
      <div className='slider'>
        <Slider
          min={0}
          max={100}
          value={value}
          onChangeStart={this.handleChangeStart}
          onChange={this.handleChange}
          onChangeComplete={this.handleChangeComplete}
        />
        <div className='value'>{value}</div>
      </div>
    )
  }
}

export default Horizontal

@ghost
Copy link

ghost commented Jul 26, 2018

I have the same problem. Thanks for the hack which works but I don't think this is a good long-term solution.

I noticed that the problem only occurs on touch devices like iPad. For me the bug doesn't happen on my desktop computer. Therefore I assume this has something to do with the all so well known ghost-click issue on mobile devices.

@maksimovicdanijel
Copy link

I can confirm that this issue is happening on Edge/ IE 11 browsers as well.

@tagyoureit
Copy link

tagyoureit commented Jan 21, 2019

I see the same behavior but I think it has to do with moving the mouse/finger only a few pixels which is technically a change but less than the amount of pixels required to change the actual value.

  handleChange = value => {
  if (this.state.value!==value) {
      this.setState({
        value
      });
    };
}

Easy and no timer required.

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

No branches or pull requests

5 participants