Skip to content

Commit 8773a49

Browse files
authored
Merge pull request #8559 from avinxshKD/fix/mouse-blur-reset
Reset mouseIsPressed on window blur
2 parents bd44550 + a33e26f commit 8773a49

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/events/pointer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function pointer(p5, fn, lifecycles){
2424
signal: this._removeSignal
2525
});
2626
}
27+
28+
window.addEventListener('blur', () => {
29+
this.mouseIsPressed = false;
30+
}, { signal: this._removeSignal });
2731
};
2832

2933
/**

test/unit/events/mouse.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ suite.todo('Mouse Events', function() {
251251
window.dispatchEvent(new MouseEvent('mousedown'));
252252
assert.strictEqual(myp5.mouseIsPressed, true);
253253
});
254+
255+
test('mouseIsPressed should reset to false on blur', function() {
256+
window.dispatchEvent(new PointerEvent('pointerdown'));
257+
assert.strictEqual(myp5.mouseIsPressed, true);
258+
window.dispatchEvent(new Event('blur'));
259+
assert.strictEqual(myp5.mouseIsPressed, false);
260+
});
254261
});
255262

256263
suite('mouseMoved', function() {

0 commit comments

Comments
 (0)