Skip to content

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)
@vercel
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
@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

3 participants