Skip to content

Commit 76e83a8

Browse files
committed
Prevent click event when item has been dragged
1 parent 63e95fe commit 76e83a8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/MouseBackend.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export default class MouseBackend {
4444
this.handleWindowMoveCapture.bind(this)
4545
this.handleWindowMoveEndCapture =
4646
this.handleWindowMoveEndCapture.bind(this)
47+
this.handleWindowClick =
48+
this.handleWindowClick.bind(this)
4749
}
4850

4951
setup() {
@@ -64,6 +66,8 @@ export default class MouseBackend {
6466
this.handleWindowMoveCapture, true)
6567
window.addEventListener('mouseup',
6668
this.handleWindowMoveEndCapture, true)
69+
window.addEventListener('click',
70+
this.handleWindowClick, true)
6771
}
6872

6973
getSourceClientOffset (sourceId) {
@@ -86,6 +90,8 @@ export default class MouseBackend {
8690
'mousemove', this.handleWindowMoveCapture, true)
8791
window.removeEventListener(
8892
'mouseup', this.handleWindowMoveEndCapture, true)
93+
window.removeEventListener(
94+
'click', this.handleWindowClick, true)
8995
}
9096

9197
connectDragSource(sourceId, node) {
@@ -187,6 +193,7 @@ export default class MouseBackend {
187193
this.moveStartSourceIds = null
188194
return
189195
}
196+
this.preventClick = true
190197

191198
e.preventDefault()
192199

@@ -197,6 +204,11 @@ export default class MouseBackend {
197204
this.actions.endDrag()
198205
}
199206

207+
handleWindowClick(e) {
208+
if (this.preventClick) e.stopPropagation()
209+
this.preventClick = false
210+
}
211+
200212
installSourceNodeRemovalObserver (node) {
201213
this.uninstallSourceNodeRemovalObserver()
202214

0 commit comments

Comments
 (0)