Skip to content

Commit 4e2decb

Browse files
committed
fixup! feat(material-experimental): MDC-based version of dialog
Potential fix for test failure in g3
1 parent c1c5bd0 commit 4e2decb

File tree

3 files changed

+225
-209
lines changed

3 files changed

+225
-209
lines changed

src/material-experimental/mdc-dialog/dialog-container.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {FocusMonitor, FocusTrapFactory} from '@angular/cdk/a11y';
1010
import {DOCUMENT} from '@angular/common';
1111
import {
12-
AfterViewInit,
1312
ChangeDetectionStrategy,
1413
ChangeDetectorRef,
1514
Component,
@@ -46,9 +45,7 @@ import {cssClasses, numbers} from '@material/dialog';
4645
'[class._mat-animation-noopable]': '!_animationsEnabled',
4746
},
4847
})
49-
export class MatDialogContainer extends _MatDialogContainerBase implements
50-
AfterViewInit, OnDestroy {
51-
48+
export class MatDialogContainer extends _MatDialogContainerBase implements OnDestroy {
5249
/** Whether animations are enabled. */
5350
_animationsEnabled: boolean = this._animationMode !== 'NoopAnimations';
5451

@@ -75,7 +72,10 @@ export class MatDialogContainer extends _MatDialogContainerBase implements
7572
super(elementRef, focusTrapFactory, changeDetectorRef, document, config, focusMonitor);
7673
}
7774

78-
ngAfterViewInit() {
75+
_initializeWithAttachedContent() {
76+
// Delegate to the original dialog-container initialization (i.e. saving the
77+
// previous element, setting up the focus trap and moving focus to the container).
78+
super._initializeWithAttachedContent();
7979
// Note: Usually we would be able to use the MDC dialog foundation here to handle
8080
// the dialog animation for us, but there are a few reasons why we just leverage
8181
// their styles and not use the runtime foundation code:
@@ -106,7 +106,11 @@ export class MatDialogContainer extends _MatDialogContainerBase implements
106106
this._waitForAnimationToComplete(this._openAnimationDuration, this._finishDialogOpen);
107107
} else {
108108
this._hostElement.classList.add(cssClasses.OPEN);
109-
this._finishDialogOpen();
109+
// Note: We could immediately finish the dialog opening here with noop animations,
110+
// but we defer until next tick so that consumers can subscribe to `afterOpened`.
111+
// Executing this immediately would mean that `afterOpened` emits synchronously
112+
// on `dialog.open` before the consumer had a change to subscribe to `afterOpened`.
113+
Promise.resolve().then(() => this._finishDialogOpen());
110114
}
111115
}
112116

0 commit comments

Comments
 (0)