-
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
fix: make sure hotkeys are not triggered outside the player or in form fields within the player #5969
Conversation
20c94a5
to
033c5f1
Compare
src/js/player.js
Outdated
|
||
this.handleHotkeys(event); | ||
// Bail out if the user is focused on an interactive form element. | ||
if (activeTag && hotkeysDisallowed.indexOf(activeTag) !== -1) { |
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 this would prevent hotkeys from working in any of the control bar buttons, no?
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 don't think so, I did try that, but I'll verify.
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.
You're right. I must have added this filtering before actually verifying it! D'oh!
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 guess you can verify if the element is contained in the control bar and then skip this check
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.
🤔
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.
Well, buttons are generally only activated on Space/Enter, which we pass through to the browser anyway. Other keys (e.g. m, f, k, etc) are unlikely to affect a button. Seems safe to allow buttons and blacklist them if it becomes an issue for whatever reason.
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, you can also define buttons as an input
tag. It may be worth doing the control bar check regardless of which elements we disallow.
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.
True, true. The control bar check seems dirty, though. I'll ponder it.
I realized that |
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.
This all LGTM, and also seems to address/fix #5774. The only thing is, I don't have an example of where it was causing problems, to see how the behavior compares after the fix, but I suppose you do?
And thanks for adding a userActions
test! This feature could definitely use some automatic testing!
Glad to hear it. It's fairly easy to reproduce if you use a page with a Video.js player embedded. If you hit the big play button then move focus into a text field or something, you can activate hotkeys when typing into the field. |
3553538
to
cba07fc
Compare
For some reason the tests are failing on BrowserStack. Will have to investigate tomorrow. |
cba07fc
to
1ef78cb
Compare
Clicking on the BPB or the poster initially no longer enables hotkeys. |
d44166a
to
3b0356e
Compare
3b0356e
to
f15e4db
Compare
…m fields within the player (videojs#5969)
Change comprises of commenting out event.stopPropagation calls added in a recent bug fix. The following comment was added in affected places: Videojs 7.5.5 has added event stopPropagation throughout its components to fix some hotkeys behaviour, such as reacting to hotkeys insie of forms inside the player. This broke our keyhandling implemenation, preventing any remote key presses from being handled. See more here: - videojs@79eadac - videojs#5969 The reasons to stop propagation don't seem to apply to our usecase, so it should be safe to leave this commented out. If this causes problems in the future, the alternative solution would perhaps be to use rewrite our key handling to go through the hotkeys system: https://github.com/videojs/video.js/blob/cf6e0e824814f3ccb061b057a9aa5eff3b54ba6e/docs/guides/options.md#useractionshotkeys
Description
We saw some issues with the recently-added hotkeys feature.
document
-levelkeydown
listeners caused players to respond to events they should not have when focus was not in the player.keydown
events which do reach the player are considered possible hotkey triggers. However, there are sometimes elements added to the player - such as in modals - that should not trigger hotkeys.Specific Changes proposed
handleKeyPress
method tohandleKeyDown
because that's more accurate. DefinehandleKeyPress
as aComponent
method that delegates tohandleKeyDown
so that any existing uses of it should not break.focus
/blur
and stop listening forkeydown
events on thedocument
. It's better to just listen forkeydown
events on the components themselves.tagName
.stopPropagation()
in key places to prevent doublekeydown
handling.Requirements Checklist