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
This commit is contained in:
Erik Thuning 2025-02-06 14:59:55 +01:00
parent 2be04e1e79
commit 3907d10755

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