Fixed event key with space (#2581)

* Fixed event key with space

* Fixed spacebar `event.key` in `controls.js`
This commit is contained in:
Roy Eden 2022-12-30 21:15:13 -03:00 committed by GitHub
parent 7c88b58a1a
commit f7d2938f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

8
src/js/controls.js vendored
View File

@ -404,7 +404,7 @@ const controls = {
'keydown keyup', 'keydown keyup',
(event) => { (event) => {
// We only care about space and ⬆️ ⬇️️ ➡️ // We only care about space and ⬆️ ⬇️️ ➡️
if (!['Space', 'ArrowUp', 'ArrowDown', 'ArrowRight'].includes(event.key)) { if (![' ', 'ArrowUp', 'ArrowDown', 'ArrowRight'].includes(event.key)) {
return; return;
} }
@ -420,12 +420,12 @@ const controls = {
const isRadioButton = matches(menuItem, '[role="menuitemradio"]'); const isRadioButton = matches(menuItem, '[role="menuitemradio"]');
// Show the respective menu // Show the respective menu
if (!isRadioButton && ['Space', 'ArrowRight'].includes(event.key)) { if (!isRadioButton && [' ', 'ArrowRight'].includes(event.key)) {
controls.showMenuPanel.call(this, type, true); controls.showMenuPanel.call(this, type, true);
} else { } else {
let target; let target;
if (event.key !== 'Space') { if (event.key !== ' ') {
if (event.key === 'ArrowDown' || (isRadioButton && event.key === 'ArrowRight')) { if (event.key === 'ArrowDown' || (isRadioButton && event.key === 'ArrowRight')) {
target = menuItem.nextElementSibling; target = menuItem.nextElementSibling;
@ -504,7 +504,7 @@ const controls = {
menuItem, menuItem,
'click keyup', 'click keyup',
(event) => { (event) => {
if (is.keyboardEvent(event) && event.key !== 'Space') { if (is.keyboardEvent(event) && event.key !== ' ') {
return; return;
} }

View File

@ -65,14 +65,14 @@ class Listeners {
return; return;
} }
if (event.key === 'Space' && matches(focused, 'button, [role^="menuitem"]')) { if (event.key === ' ' && matches(focused, 'button, [role^="menuitem"]')) {
return; return;
} }
} }
// Which keys should we prevent default // Which keys should we prevent default
const preventDefault = [ const preventDefault = [
'Space', ' ',
'ArrowLeft', 'ArrowLeft',
'ArrowUp', 'ArrowUp',
'ArrowRight', 'ArrowRight',
@ -118,7 +118,7 @@ class Listeners {
} }
break; break;
case 'Space': case ' ':
case 'k': case 'k':
if (!repeat) { if (!repeat) {
silencePromise(player.togglePlay()); silencePromise(player.togglePlay());
@ -663,7 +663,7 @@ class Listeners {
elements.buttons.settings, elements.buttons.settings,
'keyup', 'keyup',
(event) => { (event) => {
if (!['Space', 'Enter'].includes(event.key)) { if (![' ', 'Enter'].includes(event.key)) {
return; return;
} }