Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"onDrag" event not getting triggered in react.js

<div className="kat-project-user-timeline-drag-indicator-wrapper-bottom"
     onDrag={(event) => {this.dragTask(event)}}>
</div>

dragTask(event) {
  console.log("logic goes here")
}

The function is not getting called for the first time. But from second time it is working fine. I tried using, event.preventDefault(), but still it is not working.

like image 646
Amala James Avatar asked Jun 23 '16 12:06

Amala James


People also ask

How do you trigger an event in react?

To add the click event in React using plain JavaScript, you need to use addEventListener() to assign the click event to an element. Create one <button> element as ref props so that it can be accessed to trigger the click event.

How do I use onDragEnd?

Definition and UsageThe ondragend event occurs when the user has finished dragging an element or text selection. Drag and drop is a very common feature in HTML5. It is when you "grab" an object and drag it to a different location. For more information, see our HTML Tutorial on HTML5 Drag and Drop.


1 Answers

Try adding draggable="true" and see if that works:

<div draggable="true" className="kat-project-user-timeline-drag-indicator-wrapper-bottom"
 onDrag={(event) => {this.dragTask(event)}}>
</div>

dragTask(event) {
  console.log("logic goes here")
}
like image 82
Hatem Jaber Avatar answered Oct 18 '22 23:10

Hatem Jaber