Skip to content

Commit

Permalink
fix: Fix tracking of pressed keys in the UI (shaka-project#3259)
Browse files Browse the repository at this point in the history
In 77054d2, 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.
  • Loading branch information
surajkumar-sk authored Mar 22, 2021
1 parent c5af2be commit 0943c80
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0943c80

Please sign in to comment.