[useFocusVisible] Make public
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Summary 💡
Make the following helper public:
Examples 🌈
I would propose this API:
function Example() {
const { focusVisible, ref, onFocus, onBlur } = useFocusVisible();
return (
<button
ref={ref}
onFocus={onFocus}
onBlur={onBlur}
style={{
outline: focusVisible ? '2px solid dodgerblue' : 'none',
}}
>
Test
</button>
);
}
Motivation 🔦
:focus-visible
has become an essential tool for our components. However, it seems that developers won’t be able to use the built-in API before a year or two years: https://caniuse.com/#search=focus visible.
An alternative approach would be to apply the class name globally as https://github.com/WICG/focus-visible does. However, it’s probably not a gap we want to fill, the previous project already solve the pain point. The main advantage of exposing this hook is that we know folks building design UI might need it, plus we already need it, exposing it comes with little downsides: we only have to pay the upfront cost of documenting it and polishing the API.
Benchmark
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (4 by maintainers)
Top Results From Across the Web
[useFocusVisible] Make public · Issue #22425 · mui/material-ui
I have searched the issues of this repository and believe that this is not a duplicate. Summary Make the following helper public: ...
Read more >useFocusVisible – React Aria - React Spectrum Libraries
useFocusVisible handles focus interactions for the page and determines whether keyboard focus should be visible (e.g. with a focus ring).
Read more >css - How to always apply focusVisible styling on a focused ...
Now I am wondering, is it possible to use a separate <TouchRipple/> element to create the animation myself? – user3044553. Dec 18, 2020...
Read more >1162070 - Use :focus-visible in the default UA stylesheet
Issue 1162070: Use :focus-visible in the default UA stylesheet ... emilio@ has sent a PR to HTML to make this change on the...
Read more >focus-visible - npm
focus-visible. 5.2.0 • Public • Published 2 years ago ... If you do want to build from source, make sure you clone the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Don’t just make things public. They add maintenance burden and remove freedom. If nobody is asking then we shouldn’t ever make something public.
@ryancogswell Sounds like you were using
:focus-visible
for something that it wasn’t intended to solve.So I’m not against making it public because of your specific issue but because of the general problem: Any public code requires 10x the work to document properly since there will always be users who misuse it.
It doesn’t make sense to make it public as a hook since that implies for many that it is behavioral in nature which
:focus-visible
isn’t. Closing since we already have the “waiting for upvotes” label. If you need a polyfill use the “official” one just like we do: https://github.com/WICG/focus-visible