Skip to content
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

Do we want to get rid of the blue focus rings? #154

Open
critocrito opened this issue Mar 10, 2021 · 1 comment
Open

Do we want to get rid of the blue focus rings? #154

critocrito opened this issue Mar 10, 2021 · 1 comment

Comments

@critocrito
Copy link
Collaborator

At least on Chrome we have those blue focus rings around buttons and form elements. They are important for keyboard navigation but I find them horrific to look at.

Screen Shot 2021-03-10 at 10 06 39

What I usually do is to disable them and only once a user tabs I turn them on. This would look something like that:

/* In the CSS file we disable the focus rings */
body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) input:focus,
body:not(.user-is-tabbing) select:focus,
body:not(.user-is-tabbing) textarea:focus {
  outline: none;
}
// In the React root we look out for the first tab event.
const App = () => {
  const [firstTabHandled, setFirstTabHandled] = useState(false);

  // enable form focus rings when tabbing
  useEffect(() => {
    if (firstTabHandled) return;

    const handleFirstTab = (ev: KeyboardEvent) => {
      // the "I am a keyboard user" key
      if (ev.key === "Tab") {
        document.body.classList.add("user-is-tabbing");
        window.removeEventListener("keydown", handleFirstTab);
      }
    };

    window.addEventListener("keydown", handleFirstTab);
    setFirstTabHandled(true);

    return () => window.removeEventListener("keydown", handleFirstTab);
  }, [firstTabHandled]);

  return <div />;
}

@aeluteia, @ana0 how do you feel about that? Shall we implement that?

@ana0
Copy link
Member

ana0 commented Mar 11, 2021

I think this would be nice to do!

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

No branches or pull requests

2 participants