Return focus when dialog is closed to element focused before open#4095
Return focus when dialog is closed to element focused before open#4095vnbaaij merged 9 commits intomicrosoft:devfrom
Conversation
|
Just because I'm curious: what happens if I open the dialog via code somehow? Which element will be focused then? For example in my case I open a modal directly in |
|
I would say nothing happens then. I think this is done when the code from @dvoituron 's last review comment gets added |
Whatever element that is currently focused at the time that |
|
This new feature should be added to the “dev-v5” branch for the new Dialog component. |
Previously focused element is nullable
Pull Request
📖 Description
Exposes two functions to get the focused element and set focus in
dialog-utils.js. Uses that in the dialog provider to get the focused element before the dialog is created (which messes with focus), and then to reset focus after close. Dialog doesn't always close immediately, so I added a small delay.Before:
Grabacion.de.pantalla.2025-08-29.a.la.s.1.05.00.a.m.mov
After:
Grabacion.de.pantalla.2025-08-29.a.la.s.1.06.55.a.m.mov
🎫 Issues
Fixes #4094
👩💻 Reviewer Notes
You can test this using the Dialog samples.
📑 Test Plan
✅ Checklist
General
Component-specific
⏭ Next Steps