Skip to content

Commit

Permalink
fix: focus on first element when back to the settings menu (shaka-pro…
Browse files Browse the repository at this point in the history
…ject#4653)

Going to the configuration menu using the keyboard and entering some
menu, when going back the focus is lost because the first element of the
HTML tree is hidden. This makes it difficult to use the player using
accessibility shortcuts.

Closes shaka-project#4652

Co-authored-by: Gonzalo Rodriguez <[email protected]>
  • Loading branch information
gonzajet and Gonzalo Rodriguez authored Nov 4, 2022
1 parent 59d4360 commit b40b6e7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ui/settings_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Utils');
goog.require('shaka.util.Dom');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.Iterables');
goog.requireType('shaka.ui.Controls');


Expand Down Expand Up @@ -116,8 +117,16 @@ shaka.ui.SettingsMenu = class extends shaka.ui.Element {
this.eventManager.listen(this.backButton, 'click', () => {
shaka.ui.Utils.setDisplay(this.parent, true);

/** @type {!HTMLElement} */
(this.parent.childNodes[0]).focus();
const isDisplayed =
(element) => element.classList.contains('shaka-hidden') == false;

const Iterables = shaka.util.Iterables;
if (Iterables.some(this.parent.childNodes, isDisplayed)) {
// Focus on the first visible child of the overflow menu
const visibleElements =
Iterables.filter(this.parent.childNodes, isDisplayed);
/** @type {!HTMLElement} */ (visibleElements[0]).focus();
}

// Make sure controls are displayed
this.controls.computeOpacity();
Expand Down

0 comments on commit b40b6e7

Please sign in to comment.