-
Notifications
You must be signed in to change notification settings - Fork 124
Revert behavior to fix failing tests. Add arrow key support. Fixes #65, #54, #63, #44 #68
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
Conversation
| var elWithFocusRing; | ||
|
|
||
| var inputTypesWhitelist = { | ||
| 'radio': true, |
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 these have stayed in?
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. That would cause focus-ring to be applied on mouse click because these get checked during the focus event. The reverted version added them because it was checking only on keyUp.
| */ | ||
| function onKeyUp(e) { | ||
| function onKeyDown(e) { | ||
| const allowedKeys = [9, 37, 38, 39, 40]; |
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.
Can you comment each of these with what key it represents?
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's a comment above that indicates it's tab and arrow keys but yeah.
| function onKeyDown(e) { | ||
| const allowedKeys = [9, 37, 38, 39, 40]; | ||
|
|
||
| // If the user is holding down a modifier key, abort. |
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.
Suggestion: "Ignore keypresses if the user is holding down a modifier key"
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.
Fixed
| return; | ||
|
|
||
| if (e.keyCode != 9) | ||
| // If the key can't be found in the list of allowed keys, abort. |
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.
Suggestion: "Ignore keypresses which aren't related to keyboard navigation."
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.
Fixed
|
|
||
| /** | ||
| * On `focus`, add the `focus-ring` class to the target if: | ||
| * - the target received focus as a result of keyboard navigation |
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.
s/navigation/navigation, or/
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.
Fixed
|
|
||
| /** | ||
| * When the polfyill first loads, assume the user is in keyboard modality. | ||
| * If any event is received from a fine-grained pointing device (mouse, pointer, touch), |
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.
Again, touch isn't fine-grained.
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.
Fixed
| * If any event is received from a fine-grained pointing device (mouse, pointer, touch), | ||
| * turn off keyboard modality. | ||
| * This accounts for situations where focus enters the page from the URL bar. | ||
| * In that scenario, the keydown event is inconsistent, so we can't use it to detect modality. |
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 would delete this and the following two lines - more justification than necessary.
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.
Fixed
| function browserFilter(browser) { | ||
| return browser.getReleaseName() === 'stable' | ||
| && ['firefox', 'chrome'].includes(browser.getId()); | ||
| && ['chrome', 'firefox'].includes(browser.getId()); |
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.
was just double checking something. selenium-assistant stopped killing firefox 57 properly and I wasn't sure if the order in which the browsers opened/closed had anything to do with it. turns out it doesn't. the ordering doesn't matter and the issue isn't actually a show stopper. it just means if you test locally you need to close firefox when you're done. doesn't seem to bother travis though. I filed GoogleChromeLabs/selenium-assistant#105
| https://jsbin.com/cawevo/edit?html,output | ||
| Add a dummy button so Selenium can use it as the first focus target. | ||
| --> | ||
| <button id="start">Dummy</button> |
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.
It confused me a little that the id was "start" but the contents was "Dummy".
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.
Fixed
| // https://jsbin.com/cawevo/edit?html,output | ||
| it.skip('should apply .focus-ring on keyboard focus', function() { | ||
| return matchesKeyboard(); | ||
| // FF won't focus a div with contenteditable if it's the first element on the page. |
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.
That sounds like it was a lot of fun to debug 🙄
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.
robdodson
left a comment
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.
Fixed comments and pushing up to master.
| var elWithFocusRing; | ||
|
|
||
| var inputTypesWhitelist = { | ||
| 'radio': true, |
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. That would cause focus-ring to be applied on mouse click because these get checked during the focus event. The reverted version added them because it was checking only on keyUp.
| */ | ||
| function onKeyUp(e) { | ||
| function onKeyDown(e) { | ||
| const allowedKeys = [9, 37, 38, 39, 40]; |
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's a comment above that indicates it's tab and arrow keys but yeah.
| function onKeyDown(e) { | ||
| const allowedKeys = [9, 37, 38, 39, 40]; | ||
|
|
||
| // If the user is holding down a modifier key, abort. |
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.
Fixed
| return; | ||
|
|
||
| if (e.keyCode != 9) | ||
| // If the key can't be found in the list of allowed keys, abort. |
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.
Fixed
|
|
||
| document.addEventListener('keyup', onKeyUp, true); | ||
| /** | ||
| * Add a group of listeners to detect a fine-grained pointing device. |
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.
Fixed
|
|
||
| /** | ||
| * When the polfyill first loads, assume the user is in keyboard modality. | ||
| * If any event is received from a fine-grained pointing device (mouse, pointer, touch), |
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.
Fixed
| * If any event is received from a fine-grained pointing device (mouse, pointer, touch), | ||
| * turn off keyboard modality. | ||
| * This accounts for situations where focus enters the page from the URL bar. | ||
| * In that scenario, the keydown event is inconsistent, so we can't use it to detect modality. |
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.
Fixed
| https://jsbin.com/cawevo/edit?html,output | ||
| Add a dummy button so Selenium can use it as the first focus target. | ||
| --> | ||
| <button id="start">Dummy</button> |
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.
Fixed
| function browserFilter(browser) { | ||
| return browser.getReleaseName() === 'stable' | ||
| && ['firefox', 'chrome'].includes(browser.getId()); | ||
| && ['chrome', 'firefox'].includes(browser.getId()); |
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.
was just double checking something. selenium-assistant stopped killing firefox 57 properly and I wasn't sure if the order in which the browsers opened/closed had anything to do with it. turns out it doesn't. the ordering doesn't matter and the issue isn't actually a show stopper. it just means if you test locally you need to close firefox when you're done. doesn't seem to bother travis though. I filed GoogleChromeLabs/selenium-assistant#105
| // https://jsbin.com/cawevo/edit?html,output | ||
| it.skip('should apply .focus-ring on keyboard focus', function() { | ||
| return matchesKeyboard(); | ||
| // FF won't focus a div with contenteditable if it's the first element on the page. |
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 reverts the behavior that's currently on master because it was breaking mouse focus and causing most of the tests to fail. It uses a different approach to address the URL bar issue from #15 and adds support for arrow keys to address #54, #63.
This also removes the polyfill for classList. This is in accordance with the W3C's new Polyfill guidance which suggests that polyfills should not bundle other polyfills. Instead, we'll update our docs to mention that the polyfill depends on classList and users should use a service like polyfill.io to add it.
@kloots FYI because I needed to back out the previous
onKeyUpchange.