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

Conversation

alex-barstow
Copy link
Contributor

@alex-barstow alex-barstow commented Feb 1, 2018

Description

These changes address an issue where screen readers may repeatedly and redundantly read TextTrackMenuItem's control text on every texttrackchange event in some browsers.

The source of the problem is in the handleTracksChange() method of TextTrackMenuItem and its subclass OffTextTrackMenuItem, in which this.selected(true/false) gets called even if the selected state has not changed since its previous invocation.

Specific Changes proposed

  1. Create private isSelected_ property for menu items
  2. Only call .selected(true) in handleTracksChange() if !isSelected_

break;
}
}

this.selected(selected);
if (shouldBeSelected) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and and in text-text-menu-item, the two ifs can be collapsed into shouldBeSelected && !this.iSelected_

Copy link
Contributor Author

@alex-barstow alex-barstow Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, that would create scenarios where shouldBeSelected is true, isSelected_ is true, yet we would deselect the menu item. In that case where both those values are true, we should just do nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, makes sense. What about moving the check into the this.selected method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I considered it. It was kind of a toss up, but in the end I decided I found it clearer to conditionally call .selected() rather than always call it and conditionally have it do nothing, if that makes sense. I don't have a particularly strong preference, so if you find it clearer to have the logic in the selected method itself I'm happy to move it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, don't really have much preference one way or the other. @videojs/core-committers do you have any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're making this change, it seems unnecessary to allow redundant selected(false) calls as well. How about shouldBeSelected && shouldBeSelected !== this.isSelected_) for the first if and !shouldBeSelected && shouldBeSelected !== this.isSelected_ for the second?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even this:

if (shouldBeSelected !== this.isSelected_) {
  this.selected(shouldBeSelected);
}


// CaptionSettingsMenuItem does not need to handle track list change events because
// it has no concept of 'selected'
handleTracksChange(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this hopefully shouldn't be necessary because we're setting selectable to false and selected already does a check for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep. Overlooked the fact that the selectable check makes it a non-issue

gkatsev
gkatsev previously approved these changes Feb 2, 2018
@gkatsev gkatsev added patch This PR can be added to a patch release. needs: LGTM Needs one or more additional approvals labels Feb 2, 2018
@alex-barstow
Copy link
Contributor Author

@ldayananda Made those changes. Much cleaner this way, thanks. @gkatsev Want to take another look?

@@ -26,8 +26,9 @@ class MenuItem extends ClickableComponent {
super(player, options);

this.selectable = options.selectable;
this.isSelected_ = options.selected;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we need a default value here.

@gkatsev gkatsev dismissed their stale review February 5, 2018 17:04

Default value

Copy link
Contributor

@ldayananda ldayananda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkatsev gkatsev removed the needs: LGTM Needs one or more additional approvals label Feb 7, 2018
@gkatsev
Copy link
Member

gkatsev commented Feb 9, 2018

Just tested it as well
☑️ tested

@gkatsev gkatsev merged commit 6189baa into videojs:master Feb 9, 2018
@alex-barstow alex-barstow deleted the only-update-tt-selected-state-if-changed branch February 9, 2018 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed patch This PR can be added to a patch release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants