Skip to content

Commit

Permalink
fix click event flow a little. close #1755
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed May 15, 2024
1 parent 70f57d2 commit 88861b3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ export class Stage extends Container<Layer> {

// no shape detected? do nothing
if (!shape || !shape.isListening()) {
this[eventType + 'ClickStartShape'] = undefined;
return;
}

Expand Down
63 changes: 63 additions & 0 deletions test/unit/MouseEvents-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2377,4 +2377,67 @@ describe('MouseEvents', function () {
});
assert.deepEqual(stage.getPointerPosition(), { x: 60, y: 60 });
});

it('mousedown on empty then mouseup on shape', function () {
if (isNode) {
return;
}
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);

stage.on('mousedown mousemove mouseup click', function (e) {
console.log('state', e.type);
});

var rect = new Konva.Rect({
width: 50,
height: 50,
fill: 'red',
draggable: true,
});
layer.add(rect);

layer.draw();

var clicks = 0;
rect.on('click', function () {
console.log('click');
clicks += 1;
if (clicks === 2) {
debugger;
}
});

simulateMouseDown(stage, {
x: 40,
y: 40,
});

simulateMouseUp(stage, {
x: 40,
y: 40,
});

// trigger click
assert.equal(clicks, 1, 'clicks not triggered');

// mousedown outside
simulateMouseDown(stage, {
x: 60,
y: 6,
});
// move into rect
simulateMouseMove(stage, {
x: 40,
y: 40,
});
// mouseup inside rect
simulateMouseUp(stage, {
x: 40,
y: 40,
});
// it shouldn't trigger the click event!!!
assert.equal(clicks, 1, 'clicks not triggered');
});
});
6 changes: 3 additions & 3 deletions test/unit/TouchEvents-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ describe('TouchEvents', function () {
);
assert.equal(touchEnd, 1);
assert.equal(stageTouchEnd, 1);
assert.equal(stageTap, 2, 'one tap should be fired');
assert.equal(stageTap, 1, 'one tap should be fired');

assert.equal(
stageEventStack.join(' '),
'touchstart touchstart touchstart touchend tap tap',
'touchstart touchstart touchstart touchend tap',
'should fire tap after touchend'
);

Expand All @@ -481,7 +481,7 @@ describe('TouchEvents', function () {
assert.equal(touchEnd, 2);
assert.equal(touchEnd2, 1);
assert.equal(stageTouchEnd, 3);
assert.equal(stageTap, 2, 'still one tap should be fired');
assert.equal(stageTap, 1, 'still one tap should be fired');
// Don't need to check event stack here, the pointers moved so no tap is fired
});

Expand Down

0 comments on commit 88861b3

Please sign in to comment.