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 restoring focus to correct element when closing Dialog component #3365

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jul 5, 2024

Right now, we have to record when a click / mousedown / focus event happens on an element. But when you click on a non-focusable element inside of a focusable element then we record the inner element instead of the outer one.

This happens in this scenario:

<button>
  <span>click me</span>
</button>

This solves it by resolving the closest focusable element (and we fallback to the e.target as a last resort)

Fixes: #3320

Right now, we have to record when a click / mousedown / focus event happens on an element. But when you click on a non-focusable element inside of a focusable element then we record the inner element instead of the outer one.

This happens in this scenario:
```html
<button>
  <span>click me</span>
</button>
```

This solves it by resolving the closest focusable element (and we fallback to the e.target as a last resort)
Copy link

vercel bot commented Jul 5, 2024

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

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 1:24pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 1:24pm

@RobinMalfait RobinMalfait changed the title resolve focusable element when recording elements Resolve focusable element when recording elements Jul 5, 2024
@RobinMalfait RobinMalfait changed the title Resolve focusable element when recording elements Fix restoring focus to correct element when closing Dialog component Jul 5, 2024
@RobinMalfait RobinMalfait merged commit 91e9597 into main Jul 5, 2024
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-3320 branch July 5, 2024 14:14
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.

Focus not returned to triggering button when closing modal
2 participants