From 51b9861d5b8b67ec8b302e736c636269483aea54 Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Mon, 19 Aug 2019 14:57:15 -0400 Subject: [PATCH] fix: do not handle hotkeys in contenteditable elements (#6182) Exclude elements where `el.isContentEditable == true;` for hotkeys. --- src/js/player.js | 9 +++++++-- test/unit/player-user-actions.test.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 3635dc6031..5241209046 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -2938,8 +2938,10 @@ class Player extends Component { const excludeElement = (el) => { const tagName = el.tagName.toLowerCase(); - // These tags will be excluded entirely. - const excludedTags = ['textarea']; + // The first and easiest test is for `contenteditable` elements. + if (el.isContentEditable) { + return true; + } // Inputs matching these types will still trigger hotkey handling as // they are not text inputs. @@ -2956,6 +2958,9 @@ class Player extends Component { return allowedInputTypes.indexOf(el.type) === -1; } + // The final test is by tag name. These tags will be excluded entirely. + const excludedTags = ['textarea']; + return excludedTags.indexOf(tagName) !== -1; }; diff --git a/test/unit/player-user-actions.test.js b/test/unit/player-user-actions.test.js index 97e0ddea37..628996f5a7 100644 --- a/test/unit/player-user-actions.test.js +++ b/test/unit/player-user-actions.test.js @@ -410,6 +410,27 @@ QUnit.test('when userActions.hotkeys.playPauseKey can be a function', function(a assert.strictEqual(this.player.play.callCount, 1, 'has played'); }); +QUnit.test('hotkeys are ignored when focus is in a contenteditable element', function(assert) { + this.player.dispose(); + this.player = TestHelpers.makePlayer({ + controls: true, + userActions: { + hotkeys: true + } + }); + + const div = document.createElement('div'); + + div.contentEditable = 'true'; + this.player.el_.appendChild(div); + div.focus(); + + assert.expect(14); + defaultKeyTests.fullscreen(this.player, assert, false); + defaultKeyTests.mute(this.player, assert, false); + defaultKeyTests.playPause(this.player, assert, false); +}); + QUnit.test('hotkeys are ignored when focus is in a textarea', function(assert) { this.player.dispose(); this.player = TestHelpers.makePlayer({