From 3907d10755dd176138cfd9beb6ffb9d5f1a22e55 Mon Sep 17 00:00:00 2001 From: Erik Thuning <boooink@gmail.com> Date: Thu, 6 Feb 2025 14:59:55 +0100 Subject: [PATCH] FIX: multiple events triggering when using keyboard while focus is on a button Keyboard events were triggering regardless of which element had focus, which led to surprising behaviour: if the play button was focused and spacebar got pressed, two playback toggle actions were triggered - one from the keyboard listener and one from the default button activation. This is fixed by ignoring spacebar presses in the custom listener if a button has focus. Also minor stylistic change break -> return --- multiplayer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/multiplayer.js b/multiplayer.js index 18c6e07..3ee898f 100644 --- a/multiplayer.js +++ b/multiplayer.js @@ -1663,11 +1663,14 @@ input[type="range"]::-ms-track { this._root.addEventListener('keydown', (event) => { switch(event.key) { case " ": + if(event.target.nodeName === "BUTTON") { + return; + } this.togglePlayback(); break; case "ArrowRight": if(event.target === this._volumeSlider) { - break; + return; } let ahead = this._controlSource.currentTime + 5; if(ahead > this._controlSource.duration) { @@ -1677,7 +1680,7 @@ input[type="range"]::-ms-track { break; case "ArrowLeft": if(event.target === this._volumeSlider) { - break; + return; } let back = this._controlSource.currentTime - 5; if(back < 0) {