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

feat: modal dialog accessibility updates #4025

Merged
merged 9 commits into from
Feb 8, 2017
Merged

feat: modal dialog accessibility updates #4025

merged 9 commits into from
Feb 8, 2017

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Feb 2, 2017

If the modal dialog was opened and the focus was preset inside the
player, move the focus to the modal dialog.
When the modal dialog is closed, move the focus back to the previously
active element.
When focus is inside the dialog, trap tab focus. This was inspired by https://github.com/gdkraus/accessible-modal-dialog and ally.js

Still needs:

  • unit tests

@gkatsev gkatsev added the a11y This item might affect the accessibility of the player label Feb 2, 2017
@gkatsev
Copy link
Member Author

gkatsev commented Feb 2, 2017

I think this PR needs to be updated to keep the focus trapped inside the modal dialog while it's open.

@gkatsev gkatsev changed the title feat: focus modal dialog when opened feat: modal dialog accessibility updates Feb 3, 2017
*
* @private
*/
focusableEls_() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be something we could use elsewhere? Should it be in Component?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called focusableChildELs_?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a link that should be included in the comments here to explain how this works?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because using instanceof isn't great, I think it should stay here until and if we start needing it elsewhere.
focusableChildEls_ is probably more accurate.

*/
focus() {
this.el_.focus();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we already have these in master? Does this PR need a rebase for some reason? https://github.com/videojs/video.js/blob/master/src/js/component.js#L1004

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, it needs to be rebased. I had two separate PRs that both needed this.

this.previouslyActiveEl_.focus();
this.previouslyActiveEl_ = null;

this.off(document, 'keydown', this.handleKeyDown);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we always turn off the listener for keydown regardless of wether there is a previouslyActiveEl_?

Copy link
Member Author

Choose a reason for hiding this comment

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

Potentially, though, I think we only need to off it only if one exists because that's the only time we on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

unless the previouslyActiveEl_ gets disposed/removed on the player for some reason between when this gets focused and blured

*/
conditionalFocus_() {
const activeEl = document.activeElement;
const playerEl = this.player_.el_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we even need a const for this here, since it is only used in the if statement below. Doesn't matter either way though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was a bit cleaner than using the expanded form twice.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok thats fine then

Copy link
Member

@OwenEdwards OwenEdwards left a comment

Choose a reason for hiding this comment

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

I pulled all the content from the Captions Setting Dialog to test this. Pressing the Tab key works properly (focus wraps back to the first element from the last one), but pressing Shift-Tab doesn't - focus goes from the first element to the last one (the close button), but the next Shift-Tab moves focus back to the first element again, rather than to the second-to-last element.

@gkatsev
Copy link
Member Author

gkatsev commented Feb 6, 2017

Interesting. I thought I had it working right. I'll take a look at it.

If the modal dialog was opened and the focus was preset inside the
player, move the focus to the modal dialog.
When the modal dialog is closed, move the focus back to the previously
active element.
@gkatsev gkatsev dismissed OwenEdwards’s stale review February 8, 2017 06:59

Fixed it. Was pretty simple, actually. Had to make sure not to do the forward tab action when shift key was pressed. Unit tests would theoretically have caught this earlier. I'll make sure to write some before this is merged.

Copy link
Member

@OwenEdwards OwenEdwards left a comment

Choose a reason for hiding this comment

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

LGTM. I wasn't able to check the "focus returns to the element which caused the modal to open" feature, but we'll check that once we have this plugged into the rest of video.js

@gkatsev gkatsev merged commit eddc1d7 into master Feb 8, 2017
@gkatsev gkatsev deleted the modal-focus branch February 8, 2017 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y This item might affect the accessibility of the player
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants