-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
I think this PR needs to be updated to keep the focus trapped inside the modal dialog while it's open. |
* | ||
* @private | ||
*/ | ||
focusableEls_() { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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_
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/js/component.js
Outdated
*/ | ||
focus() { | ||
this.el_.focus(); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/js/modal-dialog.js
Outdated
this.previouslyActiveEl_.focus(); | ||
this.previouslyActiveEl_ = null; | ||
|
||
this.off(document, 'keydown', this.handleKeyDown); |
There was a problem hiding this comment.
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_
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thats fine then
There was a problem hiding this 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.
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.
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.
There was a problem hiding this 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
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: