zag icon indicating copy to clipboard operation
zag copied to clipboard

Incorrect focus

Open makuko opened this issue 1 year ago • 1 comments

🐛 Bug report

Opening the menu by clicking the trigger button sometimes activates :focus-visible despite not beeing a keyboard interaction.

💥 Steps to reproduce

  1. Go to the provided Stackblitz or change styling for the exampleon the website to apply the blue outline on :focus-visible instead of :focus
  2. Click on the button to open the menu.
  3. You see the blue outline applied despite using the mouse.
  4. Now click the other button effectively leaving keyboard interaction mode.
  5. When you click the menu button again it opens as expected without showing the outline.
  6. Press Esc to enter keyboard iinteraction mode again. The menu closes.
  7. Click the menu button again and the outline returns.

💻 Link to reproduction

Stackblitz

🧐 Expected behavior

:focus-visible is only triggered on keyboard interaction as it is the case for other components like select.

🌍 System information

Software Version(s)
Zag Version latest
Browser Chrome
Operating System Linux

makuko avatar Apr 27 '25 08:04 makuko

This is not something we control, as calling element.focus() can sometimes show the focus outline.

When this becomes widely supported, it will no longer become an issue. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#focusvisible

segunadebayo avatar Apr 27 '25 12:04 segunadebayo