Comments (3)
@bradkemper so, you're advocating for something like onmousedown
on a <button>
we would set focus back to the previously focused element? If so, I'm not entirely clear what user problem that would be solving. I also think what you're asking for is outside the scope of what this library is aiming to solve and a bit against the grain; we're not seeking to normalize how browsers manage focus, rather simply provide a new API for styling focus gained through keyboard actions.
While we developers are aware of the subtle differences between how focus is handled differently on Mac and Windows, those behaviors are expected by users and therefore we'd best serve users by honoring them, rather than making a Windows browser behave like a Mac browser.
That said, if you wanted to prevent any non-text input elements from gaining focus in your own applications you could implement that easily by simply binding a document-level event listener that would prevent the target from gaining focus by calling preventDefault()
. Here's a simplified example:
document.addEventListener('mousedown', function(e) {
var tagName = e.target.tagName.toLowerCase();
if (tagName == 'textarea') {
return;
}
e.preventDefault();
}, true);
If I misread your intention with this issue, can you clarify what you are asking for and what user problem you are addressing?
from focus-visible.
It is less about normalization between platforms, and more about fixing non-standard behavior within browsers of a single platform. Inasmuch as this library tries to get the browser focus rendering to look more like what focusing does in other desktop apps, I thought it would be nice to also more fully emulate the focusing behavior of other desktop apps too. Personally, I think the Mac behavior would be good on other platforms too, but if that is unexpected then maybe UA detection would be warranted.
In terms of what this behavior solves, and why Macs have it: it means that in places where you are typing into fields or areas, where you might also want to click on a button, doing so will not interrupt your typing and force you to refocus the field and insertion point. You can type some words, click on a button (imagine a toolbar button in MS Word, for example), and then continue typing. It is similar even in small text fields of OS X input sheets, such as a standard print dialog box. Changing the paper size doesn't blur the field for typing in number of copies, unless you use the keyboard to tab out of it and tab into the paper size menu. This is just standard behavior on the Mac (except in browsers), and why the focus rings are visible when they are. For mouse users, the focus ring indicates something you can type text into.
Preventing a mousedown event is likely to have some unwanted side effects, besides just focusing. For instance, the standard behavior on the Mac is that pop-up menus (SELECTs) can be activated with just a mousedown (without actually changing the focus, which is how Web pages are different), and that standard behavior would probably be prevented if preventDefault was called.
from focus-visible.
Thanks for the thoughtful discussion guys.
While we developers are aware of the subtle differences between how focus is handled differently on Mac and Windows, those behaviors are expected by users and therefore we'd best serve users by honoring them, rather than making a Windows browser behave like a Mac browser.
I agree with @kloots on this one. The :focus-ring
pseudo selector is primarily for exposing a styling hook based on input modality. @bradkemper has a good point that it's definitely quirky, but it's out of scope for this little library to try to tackle that issue. We're not trying to correct or normalize the way focus actually behaves on different platforms. If it's ok i'm going to close this issue as out of scope.
from focus-visible.
Related Issues (20)
- Don't enable polyfill if browser supports ":focus-visible" HOT 5
- List a `module` export in package.json` HOT 3
- .focus-visible skips elements on Safari HOT 4
- How to add declaration when importing as module in Rollup + Typescript? HOT 3
- Conditional Application? HOT 1
- Focus visible... but for aria-activedescendant? HOT 1
- Managed Focus in Safari
- Keyboard escape hides focus on Button ContextMenu HOT 3
- Always applies focus-visible to inputs in React even when click HOT 3
- Add hint to documentation about ES6 import
- [performance] applying the polyfill in self contained web components with light dom HOT 1
- :focus-visible's "hidden focus" artifact can result in user UI confusion on Mac HOT 13
- Default to polyfill off in Web Native cases?
- Warning when building HOT 2
- Applying :focus-visible state after programmatically moving focus only on initial page landing
- `:focus-visible` should match when focus is programmatically moved to inside a dialog HOT 3
- Memory leaks when applyFocusVisiblePolyfill is applied then the element is removed HOT 3
- Remove source map for minified build in releases
- Readme/polyfill HOT 1
- [Bug] focusVisible status is not added correctly when user interacts with keyboard and mouse
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from focus-visible.