这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@robdodson
Copy link
Collaborator

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 onKeyUp change.

@robdodson robdodson changed the title Revert behavior to fix failing tests. Add keyboard support. Fixes #65, #54, #63, #44 Revert behavior to fix failing tests. Add arrow key support. Fixes #65, #54, #63, #44 Nov 15, 2017
@robdodson robdodson merged commit 989804d into master Nov 15, 2017
var elWithFocusRing;

var inputTypesWhitelist = {
'radio': true,
Copy link
Member

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?

Copy link
Collaborator Author

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];
Copy link
Member

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?

Copy link
Collaborator Author

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.
Copy link
Member

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"

Copy link
Collaborator Author

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.
Copy link
Member

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."

Copy link
Collaborator Author

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
Copy link
Member

Choose a reason for hiding this comment

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

s/navigation/navigation, or/

Copy link
Collaborator Author

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),
Copy link
Member

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.

Copy link
Collaborator Author

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.
Copy link
Member

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.

Copy link
Collaborator Author

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());
Copy link
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Collaborator Author

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>
Copy link
Member

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".

Copy link
Collaborator Author

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.
Copy link
Member

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 🙄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@robdodson robdodson left a 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,
Copy link
Collaborator Author

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];
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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),
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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>
Copy link
Collaborator Author

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());
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants