Skip to content

Commit

Permalink
feat: focus play toggle from Big Play Btn on play (#4132)
Browse files Browse the repository at this point in the history
If the control bar and playtoggle exist, focus the playtoggle after
triggering play via the keyboard from the Big Play Button.
If the control bar isn't available, then focus the player element.
Adds focus() and blur() on components.

This is a port of #4018.

Fixes #2729 for the 5.x branch.
  • Loading branch information
gkatsev authored Feb 27, 2017
1 parent fa97309 commit dcc615a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/js/big-play-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class BigPlayButton extends Button {
*/
handleClick(event) {
this.player_.play();

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

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

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 @@ -1232,6 +1232,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 @@ -481,6 +481,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

0 comments on commit dcc615a

Please sign in to comment.