-
Notifications
You must be signed in to change notification settings - Fork 124
Clean up polyfill code; add discussion of default modality to explainer. #4
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
|
@alice, I might be wrong, but it seems you have not yet joined the WICG as a Google rep. Please visit the following link, and click "join this group". That should guide you and give you the right permissions. https://www.w3.org/community/wicg/ In the mean time, I'll mark this as non-substitantive. |
|
Marked as non-substantive for IPR from ash-nazg. |
README.md
Outdated
|
|
||
| 1. Add a new keyword value to the outline shorthand that represents whatever the default UA `::focus-ring` is. Then authors can do: | ||
|
|
||
| :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.
suggest using :focus-ring
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.
Not what you want, though. If you always want the focus ring to be shown (the use case in question), you want :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.
oh sorry I thought this was more about our whole outline: ua discussion. Like if someone says :focus { outline: none } then there's no way for :focus-ring { } to ever get the default UA styles back
README.md
Outdated
| 2. Add a new CSS property that controls "keyboard modality" vs non-"keyboard modality" behavior, e.g. | ||
|
|
||
| my-custom-texty-element { | ||
| should-show-focus-on-mouse-click-bikeshed: on-bikeshed; |
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 feel like if we do this then why have :focus-ring at all? Not saying we shouldn't do this, just that it would probably supersede whatever :focus-ring has to offer
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.
No, this complements :focus-ring by allowing you to choose when it gets matched (unlike :focus which always matches on focus regardless).
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.
OOOOOOOOH. got it. yes that would be nice. I think the way the use case was pitched didn't click in my head... also it's 1am
You may be able to rephrase it as:
In addition to `:focus-ring`, there are additional, speculative, missing primitives which may make working with focus easier.
1. An element should have a way to restore the UA default outline. Because each UA has a different default style, there's no easy way to restore the outline if a prior selector has overridden it (short of UA sniffing).
2. An element should have a way to express when it should display a focus ring. On keyboard focus, on mouse focus, or on both.
These could help explain the behavior of native text fields...
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.
Reworded.
demo/index.html
Outdated
| <p> | ||
| This page contains various html controls and demonstrates a proposal for only drawing a focus ring when the keyboard is being used. | ||
| Navigate through the interactive elements various ways (using mouse, switch to keyboard, try it on a touch device). You should see a green focus indicator (or comment out green focus ring style to see default focus ring) on elements below differently based on whether you interact with them via keyboard or mouse. If you are using the mouse and get lost, at any time you can tab/shift-tab to find your focus indicator. | ||
| Navigate through the interactive elements various ways (using mouse, switch to keyboard, try it on a touch 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.
"Navigate through the interactive elements in various ways"
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.
Yeah we accidentally a word there.
| @@ -1,67 +1,112 @@ | |||
| /* https://github.com/WICG/focusring */ | |||
| /* https://github.com/WICG/focus-ring */ | |||
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.
oops I merged my own PR that had this same change
#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.
NP 😄
| document.addEventListener('DOMContentLoaded', function() { | ||
| var hadKeyboardEvent = false, | ||
| keyboardModalityWhitelist = [ 'input:not([type])', | ||
| var hadKeyboardEvent = false; |
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.
Suggest using let and const throughout so we can be cool and hip. 🏂
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.
doesn't that mean it work work in some browsers and we'll have to go through all that pain again?
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.
yeaaaah i guess. ok can leave as var
src/focus-ring.js
Outdated
| hadKeyboardEvent = true; | ||
| // `activeElement` defaults to document.body if nothing focused, | ||
| // so check the active element is actually focused. | ||
| if (document.activeElement.matches(':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.
should this be matcher.call(document.activeElement, ':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.
derp
src/focus-ring.js
Outdated
| el.removeAttribute('data-focus-ring-added') | ||
| }; | ||
| '[role=textbox]' ].join(','); | ||
| var matcher = (function() { |
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 you mind renaming this to matches? And adding a comment linking to the MDN post https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
when I think of "matcher" my brain automatically assumes that this is already bound to a specific element. I have gone back and reread this chunk of code like 5 times and I still can't shake that feeling 😋
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 had that briefly but matches by itself looks too much like it should be a list of matches (results) to me. matcher conveys that it's a function, IMO.
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 how about matchesFunction.
src/focus-ring.js
Outdated
|
|
||
| document.body.addEventListener('focus', function(e) { | ||
| /** | ||
| * On `focus`, add the `focus-ring` class to the target if 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.
replace if necessary with if the element matches a selector in the keyboardModalityWhitelist whitelist
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.
Not accurate:
- Will also add it if focus came from keyboard and the element doesn't match the whitelist
- Will not add it if it was already there.
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.
could you add all of the above to the 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.
Why? They're implementation details.
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 I see the potential scenarios as critical pieces of information.
On `focus`, add the `focus-ring` class if one of the following scenarios is met:
- If focus came from the keyboard.
- If focus occurred before the keyboardThrottle expired.
- If the `target` is in the keyboardModalityWhitelist.
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 you convinced me.
| var hadKeyboardEvent = false; | ||
| var keyboardThrottleTimeoutID = 0; | ||
|
|
||
| var keyboardModalityWhitelist = [ 'input:not([type])', |
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 could use a comment explaining why the whitelist exists. That it's for elements we want to always display a :focus-ring for
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
@robdodson PTAL