Fix pointer events click prevention after drag and drop

Co-authored-by: lavrton <1443320+lavrton@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-24 10:37:23 +00:00
parent 46c4da126c
commit 4dafab1d14
4 changed files with 10 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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) {