mirror of
https://github.com/konvajs/konva.git
synced 2025-10-07 15:46:22 +08:00
Fix pointer events click prevention after drag and drop
Co-authored-by: lavrton <1443320+lavrton@users.noreply.github.com>
This commit is contained in:
@@ -163,11 +163,16 @@ if (Konva.isBrowser) {
|
||||
window.addEventListener('touchend', DD._endDragBefore, true);
|
||||
// add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
|
||||
window.addEventListener('touchcancel', DD._endDragBefore, true);
|
||||
window.addEventListener('pointerup', DD._endDragBefore, true);
|
||||
window.addEventListener('pointercancel', DD._endDragBefore, true);
|
||||
|
||||
window.addEventListener('mousemove', DD._drag);
|
||||
window.addEventListener('touchmove', DD._drag);
|
||||
window.addEventListener('pointermove', DD._drag);
|
||||
|
||||
window.addEventListener('mouseup', DD._endDragAfter, false);
|
||||
window.addEventListener('touchend', DD._endDragAfter, false);
|
||||
window.addEventListener('touchcancel', DD._endDragAfter, false);
|
||||
window.addEventListener('pointerup', DD._endDragAfter, false);
|
||||
window.addEventListener('pointercancel', DD._endDragAfter, false);
|
||||
}
|
||||
|
@@ -2665,7 +2665,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
_listenDrag() {
|
||||
this._dragCleanup();
|
||||
|
||||
this.on('mousedown.konva touchstart.konva', function (evt) {
|
||||
this.on('mousedown.konva touchstart.konva pointerdown.konva', function (evt) {
|
||||
const shouldCheckButton = evt.evt['button'] !== undefined;
|
||||
const canDrag =
|
||||
!shouldCheckButton || Konva.dragButtons.indexOf(evt.evt['button']) >= 0;
|
||||
|
@@ -251,7 +251,7 @@ describe('DragAndDropEvents', function () {
|
||||
// should we save several pointers per shape?
|
||||
// doesn't sound good
|
||||
// switch to pointer only event handling?
|
||||
it.skip('click should not occur after drag and drop', function (done) {
|
||||
it('click should not occur after drag and drop - pointer events', function (done) {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
|
@@ -377,7 +377,7 @@ export function simulatePointerMove(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
};
|
||||
|
||||
stage._pointermove(evt as any);
|
||||
// Konva.DD._drag(evt);
|
||||
Konva.DD._drag(evt);
|
||||
}
|
||||
|
||||
export function simulatePointerUp(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
@@ -390,9 +390,9 @@ export function simulatePointerUp(stage: Stage, pos: SimulatedPointerEvent) {
|
||||
type: 'pointerup',
|
||||
};
|
||||
|
||||
// Konva.DD._endDragBefore(evt);
|
||||
Konva.DD._endDragBefore(evt);
|
||||
stage._pointerup(evt as any);
|
||||
// Konva.DD._endDragAfter(evt);
|
||||
Konva.DD._endDragAfter(evt);
|
||||
}
|
||||
|
||||
function isClose(a, b) {
|
||||
|
Reference in New Issue
Block a user