Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: focus play toggle from Big Play Btn on play #4018

Merged
merged 2 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/js/big-play-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ class BigPlayButton extends Button {
* @listens click
*/
handleClick(event) {
this.player_.play();
const playPromise = this.player_.play();

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

if (!playToggle) {
this.player_.focus();
return;
}

if (playPromise) {
playPromise.then(() => playToggle.focus());
} else {
this.setTimeout(function() {
playToggle.focus();
}, 1);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,20 @@ class Component {
return this.currentDimension('height');
}

/**
* Set the focus to this component
*/
focus() {
this.el_.focus();
}

/**
* Remove the focus from this component
*/
blur() {
this.el_.blur();
}

/**
* Emit a 'tap' events when touch event support gets detected. This gets used to
* support toggling the controls through a tap on the video. They get enabled
Expand Down
3 changes: 3 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ class Player extends Component {
el = this.el_ = super.createEl('div');
}

// set tabindex to -1 so we could focus on the player element
tag.setAttribute('tabindex', '-1');

// Remove width/height attrs from tag so CSS can make it 100% width/height
tag.removeAttribute('width');
tag.removeAttribute('height');
Expand Down