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

Only select TextTrackMenuItem if unselected #4920

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ class OffTextTrackMenuItem extends TextTrackMenuItem {
*/
handleTracksChange(event) {
const tracks = this.player().textTracks();
let selected = true;
let shouldBeSelected = true;

for (let i = 0, l = tracks.length; i < l; i++) {
const track = tracks[i];

if ((this.options_.kinds.indexOf(track.kind) > -1) && track.mode === 'showing') {
selected = false;
shouldBeSelected = false;
break;
}
}

this.selected(selected);
// Prevent redundant selected() calls because they may cause
// screen readers to read the appended control text unnecessarily
if (shouldBeSelected !== this.isSelected_) {
this.selected(shouldBeSelected);
}
}

handleSelectedLanguageChange(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ class TextTrackMenuItem extends MenuItem {
* @listens TextTrackList#change
*/
handleTracksChange(event) {
this.selected(this.track.mode === 'showing');
const shouldBeSelected = this.track.mode === 'showing';

// Prevent redundant selected() calls because they may cause
// screen readers to read the appended control text unnecessarily
if (shouldBeSelected !== this.isSelected_) {
this.selected(shouldBeSelected);
}
}

handleSelectedLanguageChange(event) {
Expand Down
5 changes: 4 additions & 1 deletion src/js/menu/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class MenuItem extends ClickableComponent {
super(player, options);

this.selectable = options.selectable;
this.isSelected_ = options.selected || false;

this.selected(options.selected);
this.selected(this.isSelected_);

if (this.selectable) {
// TODO: May need to be either menuitemcheckbox or menuitemradio,
Expand Down Expand Up @@ -93,11 +94,13 @@ class MenuItem extends ClickableComponent {
// aria-checked isn't fully supported by browsers/screen readers,
// so indicate selected state to screen reader in the control text.
this.controlText(', selected');
this.isSelected_ = true;
} else {
this.removeClass('vjs-selected');
this.el_.setAttribute('aria-checked', 'false');
// Indicate un-selected state to screen reader
this.controlText('');
this.isSelected_ = false;
}
}
}
Expand Down