question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:

https://github.com/mui-org/material-ui/blob/a8acbad5a92dc4c8b672be8fca83049dd8df68de/packages/material-ui/src/utils/useIsFocusVisible.js#L118

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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eps1loncommented, Aug 31, 2020

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.

0reactions
eps1loncommented, Oct 26, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found