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

Conversation

@robdodson
Copy link
Collaborator

@alice PTAL

<script src="/dist/focus-visible.js"></script>
<script>
start.onclick = function() {
el.focus();
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 also add a test for focusing in a new microtask?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

@robdodson robdodson force-pushed the programmatic-focus branch 2 times, most recently from cb30b92 to da0cc0e Compare February 8, 2018 22:03
@robdodson
Copy link
Collaborator Author

Ignore the conflicts. I think I just forgot to rebase against latest master where the most recent change was some additional comments.

elementToBePointerFocused = e.target;
// Clicking inside of a <select multiple> element will fire a mousedown
// on the <option> child, but focus will be set on the <select> itself.
if (elementToBePointerFocused.nodeName == 'OPTION') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note. If we keep this change then we'll need to do something different for elements inside of shadow dom.

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 think what we can do there is .getRootNode() or whatever the API is called. If that returns a shadowRoot, we'll need to set this to the element's host.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@robdodson
Copy link
Collaborator Author

I went back to the previous approach. I moved the pointer exclusion stuff to a separate branch in case we ever want to use it.

I also added a fix and test for a small bug I found. If you press a key on an already focused element, the polyfill thinks it's in keyboard modality but it never gets cleared out because there's never a focus event. If you then click on something with a mouse, we still think we're in keyboard modality. I just added a handler for any mouse/pointer/touch down event that forces keyboard modality off.

Ready for review when you have time.

@robdodson robdodson merged commit 3d76059 into master Feb 10, 2018
@karlhorky
Copy link

First of all, thanks for this library. Really liking the polyfill efforts from standards orgs.

What issue does this pull request solve? It seems to be the cause of unusual behavior when using cmd-tab to switch away from browser windows:

  1. User has used the mouse to select elements. No focus styles applied.
  2. User hits the cmd key for a fraction of a second before hitting tab to switch to another window.
  3. Focus styles appear for this fraction of a second, causing a confusing flash of styles before the window switches.

A simple reproduction can be seen on the demo page, where a press on the cmd key after mouse-only selection causes the focus style to be applied:

Kapture 2019-04-24 at 11 56 07

The flashing of styles while using cmd-tab does not appear in version 4.0.1 of the library.


If there's a very important reason that the changes from this pull request were made, maybe there can be a smaller blacklist of modifier keys (window and tab switching keys, for example) that it won't trigger on?

@karlhorky
Copy link

I can also open this as a new issue, if that would be more appropriate.

@robdodson
Copy link
Collaborator Author

Hey @karlhorky,

I plan to follow up more but real quick, i think you'd be interested in this:
#184

We updated the heuristic so meta keys don't trigger keyboard focus. Specifically to avoid when folks are using keyboard shortcuts.

@karlhorky
Copy link

Ah cool, you're on it already! Nice 🙌. Watching now.

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.

4 participants