From 0943c80ce8098ad04ae3546454bdb63c1fee560a Mon Sep 17 00:00:00 2001 From: "Suraj kumar (sk)" <71056993+surajkumar-sk@users.noreply.github.com> Date: Mon, 22 Mar 2021 07:28:49 +0530 Subject: [PATCH] fix: Fix tracking of pressed keys in the UI (#3259) In 77054d21, we made some changes to UI keyboard events that introduced a new bug. It broke our tracking of pressed keys in the UI, which allows us to observe keyboard navigation through the UI and maintain focus when tabbing through overflow menus. This fixes the tracking of pressed keys by properly removing them from the set on keyup, not keydown events. --- ui/controls.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/controls.js b/ui/controls.js index 22119f6ee3..72e8ff097a 100644 --- a/ui/controls.js +++ b/ui/controls.js @@ -930,6 +930,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { this.onControlsKeyDown_(/** @type {!KeyboardEvent} */(e)); }); + this.eventManager_.listen(this.videoContainer_, 'keyup', (e) => { + this.onControlsKeyUp_(/** @type {!KeyboardEvent} */(e)); + }); + this.eventManager_.listen( this.adManager_, shaka.ads.AdManager.AD_STARTED, (e) => { this.ad_ = (/** @type {!Object} */ (e))['ad']; @@ -1200,9 +1204,6 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { this.onMouseMove_(event); } - // When the key is released, remove it from the pressed keys set. - this.pressedKeys_.delete(event.key); - if (!this.config_.enableKeyboardPlaybackControls) { return; } @@ -1243,6 +1244,16 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { } } + /** + * Support controls with keyboard inputs. + * @param {!KeyboardEvent} event + * @private + */ + onControlsKeyUp_(event) { + // When the key is released, remove it from the pressed keys set. + this.pressedKeys_.delete(event.key); + } + /** * Called both as an event listener and directly by the controls to initialize * the buffering state.