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
fix(material/dialog): autofocus should wait for rendering to complete #28330
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I suspect that this will be pretty breaking during the TGP.
The current implementation of the dialog's `finishDialogOpen`, which includes autofocus, only waits for a microtask before executing. This only works in the tests because of the synchronous call to `detectChanges` after opening the dialog, ensuring that change detection runs before the microtask. In an application, this is not guaranteed because `NgZone` will only run change detection when the microtask queue empties, which includes the microtask created by the dialog container. This commit updates the implementation to wait for the next render to coplete, _then_ queues a microtask that will finish the open process and perform autofocus.
97c0416
to
c721426
Compare
Yea, definitely a concern I have as well. |
Closing - after more investigation, the issue with focus is actually the focus trap, not the dialog promise here. |
Reopening - This is somewhat the responsibility of the dialog and I think the focus-trap is a separate issue. The dialog has control over what APIs in the focus trap it's calling, so it can instead call |
The current implementation of the dialog's
finishDialogOpen
, which includes autofocus, only waits for a microtask before executing. This only works in the tests because of the synchronous call todetectChanges
after opening the dialog, ensuring that change detection runs before the microtask. In an application, this is not guaranteed becauseNgZone
will only run change detection when the microtask queue empties, which includes the microtask created by the dialog container.This commit updates the implementation to wait for the next render to coplete, then queues a microtask that will finish the open process and perform autofocus.