mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 03:24:49 +08:00
Merge pull request #1933 from konvajs/codex/resolve-mouseleave-vs-pointerleave-behavior
Fix pointerleave bubbling behavior
This commit is contained in:
commit
27fc1b1ba5
17
src/Node.ts
17
src/Node.ts
@ -88,6 +88,10 @@ const ABSOLUTE_OPACITY = 'absoluteOpacity',
|
|||||||
LISTENING = 'listening',
|
LISTENING = 'listening',
|
||||||
MOUSEENTER = 'mouseenter',
|
MOUSEENTER = 'mouseenter',
|
||||||
MOUSELEAVE = 'mouseleave',
|
MOUSELEAVE = 'mouseleave',
|
||||||
|
POINTERENTER = 'pointerenter',
|
||||||
|
POINTERLEAVE = 'pointerleave',
|
||||||
|
TOUCHENTER = 'touchenter',
|
||||||
|
TOUCHLEAVE = 'touchleave',
|
||||||
NAME = 'name',
|
NAME = 'name',
|
||||||
SET = 'set',
|
SET = 'set',
|
||||||
SHAPE = 'Shape',
|
SHAPE = 'Shape',
|
||||||
@ -2335,8 +2339,17 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
evt.target = this;
|
evt.target = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nonBubbling = [
|
||||||
|
MOUSEENTER,
|
||||||
|
MOUSELEAVE,
|
||||||
|
POINTERENTER,
|
||||||
|
POINTERLEAVE,
|
||||||
|
TOUCHENTER,
|
||||||
|
TOUCHLEAVE,
|
||||||
|
];
|
||||||
|
|
||||||
const shouldStop =
|
const shouldStop =
|
||||||
(eventType === MOUSEENTER || eventType === MOUSELEAVE) &&
|
nonBubbling.indexOf(eventType) !== -1 &&
|
||||||
((compareShape &&
|
((compareShape &&
|
||||||
(this === compareShape ||
|
(this === compareShape ||
|
||||||
(this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
|
(this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
|
||||||
@ -2347,7 +2360,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
|
|
||||||
// simulate event bubbling
|
// simulate event bubbling
|
||||||
const stopBubble =
|
const stopBubble =
|
||||||
(eventType === MOUSEENTER || eventType === MOUSELEAVE) &&
|
nonBubbling.indexOf(eventType) !== -1 &&
|
||||||
compareShape &&
|
compareShape &&
|
||||||
compareShape.isAncestorOf &&
|
compareShape.isAncestorOf &&
|
||||||
compareShape.isAncestorOf(this) &&
|
compareShape.isAncestorOf(this) &&
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
simulateTouchStart,
|
simulateTouchStart,
|
||||||
simulateTouchMove,
|
simulateTouchMove,
|
||||||
simulateTouchEnd,
|
simulateTouchEnd,
|
||||||
|
simulatePointerMove,
|
||||||
compareCanvases,
|
compareCanvases,
|
||||||
createCanvas,
|
createCanvas,
|
||||||
showHit,
|
showHit,
|
||||||
@ -1222,6 +1223,36 @@ describe('Stage', function () {
|
|||||||
assert.equal(count, 2);
|
assert.equal(count, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('stage pointerleave should not fire when leaving a child', function () {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var circle = new Konva.Circle({
|
||||||
|
fill: 'red',
|
||||||
|
radius: 30,
|
||||||
|
x: 50,
|
||||||
|
y: 50,
|
||||||
|
});
|
||||||
|
layer.add(circle);
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
var stageLeave = 0;
|
||||||
|
var circleLeave = 0;
|
||||||
|
stage.on('pointerleave', function () {
|
||||||
|
stageLeave += 1;
|
||||||
|
});
|
||||||
|
circle.on('pointerleave', function () {
|
||||||
|
circleLeave += 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
simulatePointerMove(stage, { x: 50, y: 50 });
|
||||||
|
simulatePointerMove(stage, { x: 90, y: 50 });
|
||||||
|
|
||||||
|
assert.equal(circleLeave, 1, 'circle pointerleave should fire');
|
||||||
|
assert.equal(stageLeave, 0, 'stage pointerleave should not fire');
|
||||||
|
});
|
||||||
|
|
||||||
it('toDataURL with hidden layer', function () {
|
it('toDataURL with hidden layer', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
|
Loading…
Reference in New Issue
Block a user