Popover enabling `:focus-visible` state on mouse interaction
See original GitHub issueWhat 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:
- Created a year ago
- Reactions:6
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
focus-visible
styles as expectedfocus-visible
styles despite closing the modal with mouse.Tabs component:
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.