Skip to content

Commit

Permalink
Merge pull request #5526 from gnattu/remove-redundant-keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill authored May 21, 2024
2 parents 9d9b69e + 11e3bf3 commit 6da3dd7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/scripts/keyboardNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const KeyNames = {
*/
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'];

/**
* Keys used for media playback control.
*/
const MediaKeys = ['MediaRewind', 'MediaStop', 'MediaPlay', 'MediaFastForward', 'MediaTrackPrevious', 'MediaTrackNext', 'MediaPlayPause'];

/**
* Elements for which navigation should be constrained.
*/
Expand Down Expand Up @@ -89,6 +94,16 @@ export function isNavigationKey(key) {
return NavigationKeys.indexOf(key) != -1;
}

/**
* Returns _true_ if key is used for media playback control.
*
* @param {string} key - Key name.
* @return {boolean} _true_ if key is used for media playback control.
*/
export function isMediaKey(key) {
return MediaKeys.includes(key);
}

/**
* Returns _true_ if the element is interactive.
*
Expand All @@ -108,6 +123,7 @@ export function isInteractiveElement(element) {
}

export function enable() {
const hasMediaSession = 'mediaSession' in navigator;
window.addEventListener('keydown', function (e) {
const key = getKeyName(e);

Expand All @@ -116,6 +132,11 @@ export function enable() {
return;
}

// Ignore Media Keys for non-TV platform having MediaSession API
if (!browser.tv && isMediaKey(key) && hasMediaSession) {
return;
}

let capture = true;

switch (key) {
Expand Down

0 comments on commit 6da3dd7

Please sign in to comment.