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

Fix restore focus to buttons in Safari, when Dialog component closes #2326

Merged
merged 5 commits into from
Mar 3, 2023

Conversation

RobinMalfait
Copy link
Collaborator

This PR fixes an issue in Safari where the focus is not properly restored to the element that originally opened the Dialog component.

This is because Safari doesn't "focus", the button when you click on it. We were relying on this (because we used the document.activeElement).

Now we will keep track of "focused" items (even when you click them), and use that as a restoreable element.

Fixes: #1643

@vercel
Copy link

vercel bot commented Mar 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 3, 2023 at 2:18PM (UTC)
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 3, 2023 at 2:18PM (UTC)

Includes a generic `Button` component that has explicit focus styles.
Safari doesn't "focus" buttons when you mousedown on them. This means
that we don't capture the correct element to restore focus to when
closing a `Dialog` for example.

Now, we will make sure to keep track of a list of last "focused" items.
We do this by also capturing elements when you "click", "mousedown" or
"focus".
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 this pull request may close these issues.

Dialog doesn't restore focus to the trigger button on Safari
2 participants