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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus outline out of sync when <Tab> contains a <Dialog> #2406

Closed
martenbjork opened this issue Mar 31, 2023 · 3 comments 路 Fixed by #2456
Closed

Focus outline out of sync when <Tab> contains a <Dialog> #2406

martenbjork opened this issue Mar 31, 2023 · 3 comments 路 Fixed by #2456
Assignees

Comments

@martenbjork
Copy link

martenbjork commented Mar 31, 2023

What package within Headless UI are you using?

@headlessui/react 馃グ

What version of that package are you using?

1.7.13

What browser are you using?

Chrome 111.0.5563.146

Reproduction URL

https://codesandbox.io/s/95yvmg

Describe your issue

When a <Tab.Panel> contains a <Dialog> the focus order appears to break.

Steps to reproduce:

  • In the demo linked above, click the first tab
  • Cycle through the tabs using the right-arrow key
  • Tab 2 contains a <Dialog>
  • Press the right-arrow again. Tab number 3 is rendered, but focus remains on <Tab> number 2. If you press right-arrow again, focus catches up and moves to the correct tab.
tab-focus.mov
@martenbjork martenbjork changed the title Focus outline gets confused when <Tab> contains a <Dialog> Focus outline out of sync when <Tab> contains a <Dialog> Mar 31, 2023
@milhamm
Copy link
Contributor

milhamm commented Apr 26, 2023

I notice this also. I think since the Dialog component has a FocusTrap component under the hood that keeps track of the focused element.

While I do think this issue should be fixed, you can try a workaround by conditionally rendering the Dialog component only when the isOpen state is true.

Example: https://codesandbox.io/s/happy-dhawan-4opgbq

@RobinMalfait
Copy link
Collaborator

Hey, thank you for this bug report! 馃檹

There was a bug in the underlying FocusTrap component that was partially activated and tried to restore the focus to the last known focused element even though the it shouldn't have been enabled in the first place.

This should be fixed by #2456, and will be available in the next release.

You can already try it using:

  • npm install @headlessui/react@insiders.
  • npm install @headlessui/vue@insiders.

@martenbjork
Copy link
Author

Aces, thanks a bunch, Robin! Excited to see this fixed! 馃檶

Thanks @milhamm for your solution as well!

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

Successfully merging a pull request may close this issue.

3 participants