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

focus-visible on tab is triggered on first click after page load #3053

Closed
PutziSan opened this issue Mar 25, 2024 · 1 comment
Closed

focus-visible on tab is triggered on first click after page load #3053

PutziSan opened this issue Mar 25, 2024 · 1 comment

Comments

@PutziSan
Copy link

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

For example: 1.7.14

What browser are you using?

Chrome

Reproduction URL

https://codesandbox.io/p/devbox/wizardly-ellis-gdt2yz?workspaceId=e9e97430-4fba-4d6b-bb93-e45d36d9e0b8

Describe your issue

  1. Press the sandbox internal refresh button
  2. Press one of the tabs

Expected Result: They should not get focus-visible (in my case blue background caused by <Tab className="focus-visible:bg-blue-500">Tab 1</Tab>)

Actual Result: Tab will get a blue background

After clicking around a bit at some point it will stop to activate the focus-visible state when clicking on the tab.

This could be part of this browser-bug (or expected behaviour? whatever): w3c/csswg-drafts#5885

@adamwathan
Copy link
Member

Hey! This is unfortunately unavoidable, we have to do a lot of programmatic focusing in Headless UI and the browser triggers focus-visible even when we wish it wouldn't.

Our recommended solution is to use the @headlessui/tailwindcss plugin and the ui-focus-visible variant instead, which relies on the presence of a data attribute that we fully control:

<Tab className="ui-focus-visible:bg-blue-500"Tab 1</Tab>

Check out this PR for more details: #2347

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