-
Notifications
You must be signed in to change notification settings - Fork 776
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
Focus trap lost when you click an item and remove it #1498
Comments
This actually looks like a bug in Chrome, as Firefox and Safari don't raise a Not sure how they handle it, because CleanShot.2022-07-07.at.17.12.34.mp4Because no events are raised on those, we wouldn't be able to strictly control the focused element anyway. |
Is that true in a Dialog as well? |
This is an example in |
We handle everything when the dialog is unmounted so I think ultimately this is a product responsibility. |
FWIW I think the real issue with Radix is not the dialog losing focus, but that it allows focus to resume "behind" the dialog. That just shouldn't be possible if it was actually trapped. |
@benoitgrelard could the focus trap do something like the following to solve this? document.addEventListener('focusout', (event) => {
if (event.relatedTarget === null) container.focus();
}) |
@jjenzz from my previous comment here: #1498 (comment)
So looks like in theory it might work because even though However, I remember trying exactly what you did here from within I'll give it another spin soon. |
Reopening, will see if we can do what's above. |
Ok I finally found a solution for this: #2145 |
Hey @benoitgrelard Solution with This is Vue example :) but it has exactly the same logic and 99% RadixUI also has this problem. Similar issue in RadixUI - #2436 |
I'm experiencing this exact issue |
I've tested the fix for the linked radix-vue` PR and it seems to work function handleMutations(mutations) {
const isLastFocusedElementExist = container1.contains(lastFocusedElementRef.current)
if (!isLastFocusedElementExist) {
$d3863c46a17e8a28$var$focus(container1)
}
} |
@benoitgrelard should I make a PR? |
Bug report
Current Behavior
If you click an item and remove it, the focus gets set to the browser's Url bar.
When you tab back into the body content, you can tab to elements that are behind the focus trap.
Expected behavior
Focus shouldn't go to the Url bar after removing an item.
If it does, you should return to the focus trap instead of elements outside it.
Reproducible example
Code:
https://codesandbox.io/s/hardcore-stitch-ne0g0n?file=/App.js
Easier to reproduce fullscreen:
https://ne0g0n.csb.app/
Additional context
Previously I've been using
focus-trap-react
and it didn't have the same issue. Focus doesn't go to the Url bar when items are removed, and if you manually focus the Url bar, you will return to the tab trap straight away.Your environment
The text was updated successfully, but these errors were encountered: