Fix issue where enter key wasn’t setting focus correctly

This commit is contained in:
Sam Potts
2018-08-05 22:41:21 +10:00
parent 4ea458e1a3
commit 0bc6b1f1b3
3 changed files with 50 additions and 37 deletions

View File

@ -553,6 +553,9 @@ class Listeners {
// Settings menu - click toggle
this.bind(elements.buttons.settings, 'click', event => {
// Prevent the document click listener closing the menu
event.stopPropagation();
controls.toggleMenu.call(player, event);
});
@ -563,8 +566,16 @@ class Listeners {
elements.buttons.settings,
'keyup',
event => {
const code = event.which;
// We only care about space and return
if (event.which !== 32 && event.which !== 13) {
if (![13, 32].includes(code)) {
return;
}
// Because return triggers a click anyway, all we need to do is set focus
if (code === 13) {
controls.focusFirstMenuItem.call(player, null, true);
return;
}
@ -572,15 +583,13 @@ class Listeners {
event.preventDefault();
// Prevent playing video (Firefox)
if (event.which === 32) {
event.stopPropagation();
}
event.stopPropagation();
// Toggle menu
controls.toggleMenu.call(player, event);
},
null,
false,
false, // Can't be passive as we're preventing default
);
// Escape closes menu