-
Notifications
You must be signed in to change notification settings - Fork 446
Return focus when dialog is closed to element focused before open #4095
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
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
@microsoft-github-policy-service agree |
@microsoft-github-policy-service rerun |
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