davidsa / drag-scroll-provider

React component for enabling scroll with the mouse
MIT License
16 stars 2 forks source link

Prevent click propagation on drag and drop #14

Closed stvmachine closed 4 years ago

stvmachine commented 5 years ago

I was wondering if anyone had an issue with click event being fired after drag and drop.

Is there an easy way to prevent this from happening?

stvmachine commented 5 years ago

So, my solution to this problem is something like this:


componentDidMount(){
   ...
   this.addEventListenerWithClear("click", this.handleOnClick);
}

 handleOnClick = e => {
    const { time } = this.privateState;
    // don't do nothing with the click event
    if (!time || time > this.threshold) {
      if (e.stopPropagation) e.stopPropagation();
      if (e.preventDefault) e.preventDefault();
      e.cancelBubble = true;
      e.returnValue = false;
      return false;
    }
    // just let the click event happens

  };
davidsa commented 5 years ago

hey @stvmachine sorry for not responding in a long time, for some reason i didn't get an email from this, did you solve this issue? are you using the clickItem callback ?