Skip to content

Commit f507c89

Browse files
gonzajetGonzalo Rodriguez
authored andcommitted
fix: focus on first element when back to the settings menu (#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 #4652 Co-authored-by: Gonzalo Rodriguez <pgonzalorodriguez@gmail.com>
1 parent f02e25a commit f507c89

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ui/settings_menu.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ goog.require('shaka.ui.Enums');
1212
goog.require('shaka.ui.Utils');
1313
goog.require('shaka.util.Dom');
1414
goog.require('shaka.util.FakeEvent');
15+
goog.require('shaka.util.Iterables');
1516
goog.requireType('shaka.ui.Controls');
1617

1718

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

119-
/** @type {!HTMLElement} */
120-
(this.parent.childNodes[0]).focus();
120+
const isDisplayed =
121+
(element) => element.classList.contains('shaka-hidden') == false;
122+
123+
const Iterables = shaka.util.Iterables;
124+
if (Iterables.some(this.parent.childNodes, isDisplayed)) {
125+
// Focus on the first visible child of the overflow menu
126+
const visibleElements =
127+
Iterables.filter(this.parent.childNodes, isDisplayed);
128+
/** @type {!HTMLElement} */ (visibleElements[0]).focus();
129+
}
121130

122131
// Make sure controls are displayed
123132
this.controls.computeOpacity();

0 commit comments

Comments
 (0)