diff options
author | Sam Potts <sam@potts.es> | 2017-11-07 23:23:17 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2017-11-07 23:23:17 +1100 |
commit | 1a5f4b1b9e1b2b8b316997c4be33d9af240e1383 (patch) | |
tree | 4bc660a5f04ea0908c01d32ee4730fe19fc10c83 /src/js/utils.js | |
parent | 3f41a0cf5417a3047aafa27894b57fb740d7d7da (diff) | |
parent | 966ca1acc30d87e1b821d78cfddc35ca75557eff (diff) | |
download | plyr-1a5f4b1b9e1b2b8b316997c4be33d9af240e1383.tar.lz plyr-1a5f4b1b9e1b2b8b316997c4be33d9af240e1383.tar.xz plyr-1a5f4b1b9e1b2b8b316997c4be33d9af240e1383.zip |
Merge branch 'develop' of github.com:Selz/plyr into develop
# Conflicts:
# dist/plyr.js
# dist/plyr.js.map
# src/js/defaults.js
Diffstat (limited to 'src/js/utils.js')
-rw-r--r-- | src/js/utils.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/js/utils.js b/src/js/utils.js index 1c3d6ed8..02f97d5a 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -433,7 +433,7 @@ const utils = { // Trap focus inside container trapFocus() { - const tabbables = utils.getElements.call(this, 'input:not([disabled]), button:not([disabled])'); + const tabbables = utils.getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]'); const first = tabbables[0]; const last = tabbables[tabbables.length - 1]; @@ -441,17 +441,22 @@ const utils = { this.elements.container, 'keydown', event => { - // If it is tab - if (event.which === 9 && this.fullscreen.active) { - if (event.target === last && !event.shiftKey) { - // Move focus to first element that can be tabbed if Shift isn't used - event.preventDefault(); - first.focus(); - } else if (event.target === first && event.shiftKey) { - // Move focus to last element that can be tabbed if Shift is used - event.preventDefault(); - last.focus(); - } + // Bail if not tab key or not fullscreen + if (event.key !== 'Tab' || event.keyCode !== 9 || !this.fullscreen.active) { + return; + } + + // Get the current focused element + const focused = utils.getFocusElement(); + + if (focused === last && !event.shiftKey) { + // Move focus to first element that can be tabbed if Shift isn't used + first.focus(); + event.preventDefault(); + } else if (focused === first && event.shiftKey) { + // Move focus to last element that can be tabbed if Shift is used + last.focus(); + event.preventDefault(); } }, false |