Skip to content

Commit

Permalink
fix: only change focus from BPB if not a mouse click (#4497)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Jul 26, 2017
1 parent fe95a77 commit ee014e2
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/js/big-play-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import Component from './component.js';
* @extends Button
*/
class BigPlayButton extends Button {
constructor(player, options) {
super(player, options);

this.mouseused_ = false;

this.on('mousedown', this.handleMouseDown);
}

/**
* Builds the default DOM `className`.
Expand All @@ -36,6 +43,11 @@ class BigPlayButton extends Button {
handleClick(event) {
const playPromise = this.player_.play();

// exit early if clicked via the mouse
if (this.mouseused_ && event.clientX && event.clientY) {
return;
}

const cb = this.player_.getChild('controlBar');
const playToggle = cb && cb.getChild('playToggle');

Expand All @@ -44,14 +56,26 @@ class BigPlayButton extends Button {
return;
}

if (playPromise) {
playPromise.then(() => playToggle.focus());
const playFocus = () => playToggle.focus();

if (playPromise && playPromise.then) {
const ignoreRejectedPlayPromise = () => {};

playPromise.then(playFocus, ignoreRejectedPlayPromise);
} else {
this.setTimeout(function() {
playToggle.focus();
}, 1);
this.setTimeout(playFocus, 1);
}
}

handleKeyPress(event) {
this.mouseused_ = false;

super.handleKeyPress(event);
}

handleMouseDown(event) {
this.mouseused_ = true;
}
}

/**
Expand Down

0 comments on commit ee014e2

Please sign in to comment.