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

Use :focus-visible instead of :focus in stylesheets #390

Open
davwheat opened this issue May 4, 2021 · 3 comments
Open

Use :focus-visible instead of :focus in stylesheets #390

davwheat opened this issue May 4, 2021 · 3 comments

Comments

@davwheat
Copy link

davwheat commented May 4, 2021

We should use :focus-visible instead of :focus to style the tabs on focus. This pseudoclass is only true when focus is gained via keyboard navigation, not by any other method, and is how focus is handled on native elements, like buttons and links.

This isn't supported in Safari, so we need to perform some acrobatics to keep the old styles working in that browser.

button:focus {
  /* our focus styles */
}

button:focus:not(:focus-visible) {
  /* UNDO our focus styles */
}

Read more:

@brennanho
Copy link

Has there been any updates on this @davwheat or have you been able to find a work around? I need to accomplish exactly what you described but applying the focus:not(:focus-visible) on my Tab elements don't seem to do the trick.

@davwheat
Copy link
Author

davwheat commented Mar 15, 2022

I personally ended up switching to another Tabs library for my project.

I wrote a wrapping component so it was quite easy to swap out: https://github.com/davwheat/personal-portfolio/blob/a7a932e355893a23f9187a92648a4af6d549e8aa/src/components/Tabs.tsx

@danez
Copy link
Collaborator

danez commented Apr 2, 2022

The styles have changed since this was reported, we do not set any style on focus anymore. I tried :focus-visible but couldn't get it reliably to work. Sometimes it would also trigger on click.

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

3 participants