You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When opening a Dialog by clicking on a button with its content wrapped in a span, focus is not properly restored to the triggering button after the dialog closes. Focus is instead returned to body.
I believe this is due to the span element being added as the latest focused element in the active element history, and when trying to focus the span the browser falls back to focusing body instead.
A solution could be to find the first focusable element in the history array and trying to focus that? Something like this:
Hey thanks for the bug report, your idea is a good idea, but instead of checking if the element is the focusable element when figuring out the element to restore, I resolved the closest focusable element when recording the click instead.
This should be fixed by #3365, and will be available in the next release.
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.7.17 - v.2.x.x
What browser are you using?
Chrome
Reproduction URL
Sandbox
Describe your issue
When opening a Dialog by clicking on a button with its content wrapped in a
span
, focus is not properly restored to the triggering button after the dialog closes. Focus is instead returned tobody
.I believe this is due to the
span
element being added as the latest focused element in the active element history, and when trying to focus thespan
the browser falls back to focusingbody
instead.A solution could be to find the first focusable element in the history array and trying to focus that? Something like this:
Here:
headlessui/packages/@headlessui-react/src/components/focus-trap/focus-trap.tsx
Line 271 in 6ac6930
What do you think? I can open a PR if I'm not missing something important here.
The text was updated successfully, but these errors were encountered: