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

Regression in @floating-ui/react@0.26.10 and return focus #2874

Closed
aversini opened this issue Apr 24, 2024 · 2 comments · Fixed by #2876
Closed

Regression in @floating-ui/react@0.26.10 and return focus #2874

aversini opened this issue Apr 24, 2024 · 2 comments · Fixed by #2876
Labels
bug Something is not working.

Comments

@aversini
Copy link

aversini commented Apr 24, 2024

Describe the bug

I'm using the Dropdown Menu example.
Accessibility rules are requiring that the triggering element that opens the menu should receive it back when the menu is closed. This was working well until and including version @floating-ui/react@0.26.9.

Versions @floating-ui/react@0.26.10 (and above) are breaking that behavior.

To Reproduce

Steps to reproduce the behavior (do not use Safari):

  1. Go to https://codesandbox.io/p/sandbox/dank-wave-cfsdqy
  2. Click on the first button, the focus ring indicates it is focused.
  3. Click on the second button to open the menu.
  4. Click on the second button again, to close the menu.

Expected behavior

  • the Menu button should be focused.

Actual behavior

  • The first button gets the focus back.

Context:

  • OS: Mac / Windows
  • Browser Chrome
  • Version 122

Additional context

  • I'm not looking at Safari since this browser does not report visible focus on click of a button.
  • With the exact same example code, simply switching from @floating-ui/react@0.26.10 to @floating-ui/react@0.26.9 resolves the issue (focus remains on the Menu button, when the menu is closed).
@atomiks
Copy link
Collaborator

atomiks commented Apr 27, 2024

This is due to the reference not being focused initially, since it opens on mousedown in which the useClick hook prevents it from recieving focus. The change caused it to use the actual previously focused element instead, but the reference is still likely more appropriate here.

Fix: #2876

@atomiks atomiks added the bug Something is not working. label Apr 28, 2024
@aversini
Copy link
Author

Thanks for the quick fix @atomiks! I just tried it, it's all fixed 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
2 participants