You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MdDialogRef.afterClosed() emits before dialog refocuses on an underlying element #3890
The MdDialogRef.afterClosed() observable emits an event before the MdDialogContainer has restored focus to an underlying element. This can cause problems if subscriptions to MdDialogRef.afterClosed() involve triggering focus events themselves.
This happens because MdDialogContainer waits for the NgZone's onMicrotaskEmpty to emit before executing its refocus operation.
What is the expected behavior?
If this is the intended behaviour then I believe it should be made explicit in the documentation. Otherwise, the MdDialogRef.afterClosed() observable should only emit once all dialog cleanup has been completed.
Currently, the documentation says:
afterClosed - Gets an observable that is notified when the dialog is finished closing.
What is the current behavior?
See above
What are the steps to reproduce?
See this plunker. AppComponent wants to focus its input element after the dialog has closed but this event is overwritten by MdDialogContainer, which restores focus to the button element.
What is the use-case or motivation for changing an existing behavior?
The contract with MdDialogRef.afterClosed() should be clear.
I am using MdDialog within the context of an application that refocuses elements in a non-trivial way so it would not be possible to control this behaviour through tabindex attributes.
Which versions of Angular, Material, OS, browsers are affected?
Tested on Angular 4.0.1/Material head f40296e/Windows 7/Chrome 57
Is there anything else we should know?
The workaround I am using is to perform the focus event inside another NgZone.onMicrotaskEmpty subscription:
changed the title [-]`MdDialogRef.afterClosed()` emits before dialog is fully closed[/-][+]`MdDialogRef.afterClosed()` emits before dialog refocuses on an underlying element[/+]on Apr 4, 2017
The issue seems to be with the animations module @dbandstra. You can work around it either by using closeAll to close all of the dialogs, or wrapping the final dialogRef.close call in a setTimeout.
angular-automatic-lock-bot commented on Sep 5, 2019
Activity
[-]`MdDialogRef.afterClosed()` emits before dialog is fully closed[/-][+]`MdDialogRef.afterClosed()` emits before dialog refocuses on an underlying element[/+]crisbeto commentedon Apr 25, 2017
Sounds weird @dbandstra, I'll take a look. Also, if you want to close all your open dialogs, you can use MdDialog.closeAll.
crisbeto commentedon Apr 29, 2017
I wasn't able to reproduce your issue @dbandstra. Here's what I tried:
Can you post a Plunkr that shows it? Also I'll close this issue since it should've been fixed by #3875.
crisbeto commentedon May 4, 2017
Thanks, that's definitely a bug. I'll look into it.
crisbeto commentedon May 8, 2017
The issue seems to be with the animations module @dbandstra. You can work around it either by using
closeAllto close all of the dialogs, or wrapping the finaldialogRef.closecall in a setTimeout.angular-automatic-lock-bot commentedon Sep 5, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.