[Dialog] Closing controlled dialog does not return focus properly
See original GitHub issueBug report
Current Behavior
When closing the Dialog via <kbd>Escape</kbd>, focus correctly restores to the trigger. However, if you activate and close the Dialog via a keybind, for example, closing the Dialog does not seem to restore focus anywhere. Even global event listeners on window
do not work.
Here’s an example:
- Open and close via click and Escape, works fine
- Open via ⌘K, listeners work while it’s open
- Close via ⌘K, listeners stop working entirely
- Click on the body, listeners start working again
Expected behavior
Focus should be restored to the body (or the trigger? not sure) in a way such that global window listeners still work. I’m not even sure how it’s possible that it doesn’t work right now.
Reproducible example
https://codesandbox.io/s/infallible-curie-8gkof?file=/src/App.tsx
Suggested solution
Change the way focus is restored on unmount
Additional context
N/A
Your environment
Software | Name(s) | Version |
---|---|---|
Radix Package(s) | dialog | 0.0.5 |
React | n/a | |
Browser | n/a | |
Assistive tech | n/a | |
Node | n/a | |
npm/yarn | n/a | |
Operating System | n/a |
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Closing dialog does not return focus to the original element.
When a dialog opens, anything outside of it should not be focusable. The only way to open another dialog would be from the...
Read more >Dialog doesn't properly close when initiated by focus
Upon closing a dialog, focus is automatically returned to the element that had focus when the dialog was opened.
Read more >Where should keyboard focus after closing a dialog with the ...
The focus should go to the next item. In that way you can go easily go through each item and delete it.
Read more >Focus restore on dialog close can cause unwanted scrolling
If the originally-focused element is not in view at the time of closing the dialog, this call to .focus() will result in it...
Read more >298078 - When a modal dialog is closed, focus should return ...
Issue 298078: When a modal dialog is closed, focus should return to the element that had focus when it was opened · 1)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m going to investigate this a little more, thanks for bringing this up @raunofreiberg!
Confirmed that it’s working now, thanks!