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.

Popover enabling `:focus-visible` state on mouse interaction

See original GitHub issue

What package within Headless UI are you using?

@headlessui/react @headlessui/vue

What version of that package are you using?

v1.6.6

What browser are you using?

Chrome

Reproduction URL

https://headlessui.com/react/popover https://stackblitz.com/edit/vitejs-vite-93uk6f?file=src/App.jsx

Describe your issue

When I click Popover.Button it enables :focus-visible state. AFAIK it should do that only with keyboard interactions. At least that’s how regular HTML buttons work.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
sibbngcommented, Jul 21, 2022

Removing the following lines fixes the issue. In my opinion these manual focus calls are unnecessary. If I click somewhere with my mouse, I know where my focus is going to.

https://github.com/tailwindlabs/headlessui/blob/5af3bd4b7164a0205ac70c179d8e9651afbb0a72/packages/%40headlessui-react/src/components/popover/popover.tsx#L266-L269 https://github.com/tailwindlabs/headlessui/blob/5af3bd4b7164a0205ac70c179d8e9651afbb0a72/packages/%40headlessui-react/src/components/popover/popover.tsx#L422

Also there are similar focus related issues with other components too.

Modal component:

  1. Click “Open Dialog”
  2. Press Tab on your keyboard, “Got it, thanks!” button will get its focus-visible styles as expected
  3. Click outside
  4. Unexpectedly “Open Dialog” button has focus-visible styles despite closing the modal with mouse.

Tabs component:

  • Clicking on the second tab will cause focus flash around the tab.
5reactions
adamwathancommented, Sep 3, 2022

Hoping we can improve this but it might be out of our hands — we do need to programmatically focus things a lot in Headless UI for accessibility reasons and often the browser treats that programmatic focusing as if it were keyboard driven and triggers a focus indicator even though I totally agree that we don’t want it to.

On our own sites we use the PostCSS focus-visible polyfill still and not the native :focus-visible pseudo class because it behaves better in this way. Fingers crossed there’s some trick we can come up with that works though — hate seeing focus styles when using the mouse.

Read more comments on GitHub >

github_iconTop Results From Across the Web

focus-visible - CSS: Cascading Style Sheets - MDN Web Docs
The :focus-visible pseudo-class applies while an element matches the :focus pseudo-class and the UA (User Agent) determines via heuristics that ...
Read more >
javascript - How to keep showing the 'popover' on hovering on ...
I believe the issue is not gaining focus. If you use onClick as the trigger, you'll find you can't actually click the Popover...
Read more >
Accessibility Examples: Popover Widget - GitHub Pages
A popover must indicate if it is expanded (visible) or collapsed (hidden) and the trigger for the popover must be associated with the...
Read more >
Popovers · Bootstrap v5.0
Use the focus trigger to dismiss popovers on the user's next click of a different element than the toggle element. Specific markup required...
Read more >
The :focus-visible Trick | CSS-Tricks
Always worth repeating: all interactive elements should have a focus style. That way, a keyboard user can tell when they have moved focus...
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