Skip to content

Commit

Permalink
fix: do not handle hotkeys in contenteditable elements (#6182)
Browse files Browse the repository at this point in the history
Exclude elements where `el.isContentEditable == true;` for hotkeys.
  • Loading branch information
misteroneill authored and gkatsev committed Aug 19, 2019
1 parent 549552e commit 51b9861
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
};

Expand Down
21 changes: 21 additions & 0 deletions test/unit/player-user-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 51b9861

Please sign in to comment.