MCPcopy Create free account
hub / github.com/angular/components / MatDialogContainer

Class MatDialogContainer

src/material/dialog/dialog-container.ts:66–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64 },
65})
66export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> implements OnDestroy {
67 /** Emits when an animation state changes. */
68 _animationStateChanged = new EventEmitter<LegacyDialogAnimationEvent>();
69
70 /** Whether animations are enabled. */
71 _animationsEnabled = !_animationsDisabled();
72
73 /** Number of actions projected in the dialog. */
74 protected _actionSectionCount = 0;
75
76 /** Host element of the dialog container component. */
77 private _hostElement: HTMLElement = this._elementRef.nativeElement;
78 /** Duration of the dialog open animation. */
79 private _enterAnimationDuration = this._animationsEnabled
80 ? (parseCssTime(this._config.enterAnimationDuration) ?? OPEN_ANIMATION_DURATION)
81 : 0;
82 /** Duration of the dialog close animation. */
83 private _exitAnimationDuration = this._animationsEnabled
84 ? (parseCssTime(this._config.exitAnimationDuration) ?? CLOSE_ANIMATION_DURATION)
85 : 0;
86 /** Current timer for dialog animations. */
87 private _animationTimer: ReturnType<typeof setTimeout> | null = null;
88
89 protected override _contentAttached(): void {
90 // Delegate to the original dialog-container initialization (i.e. saving the
91 // previous element, setting up the focus trap and moving focus to the container).
92 super._contentAttached();
93
94 // Note: Usually we would be able to use the MDC dialog foundation here to handle
95 // the dialog animation for us, but there are a few reasons why we just leverage
96 // their styles and not use the runtime foundation code:
97 // 1. Foundation does not allow us to disable animations.
98 // 2. Foundation contains unnecessary features we don't need and aren't
99 // tree-shakeable. e.g. background scrim, keyboard event handlers for ESC button.
100 this._startOpenAnimation();
101 }
102
103 /** Starts the dialog open animation if enabled. */
104 private _startOpenAnimation() {
105 this._animationStateChanged.emit({state: 'opening', totalTime: this._enterAnimationDuration});
106
107 if (this._animationsEnabled) {
108 this._hostElement.style.setProperty(
109 TRANSITION_DURATION_PROPERTY,
110 `${this._enterAnimationDuration}ms`,
111 );
112
113 // We need to give the `setProperty` call from above some time to be applied.
114 // One would expect that the open class is added once the animation finished, but MDC
115 // uses the open class in combination with the opening class to start the animation.
116 this._requestAnimationFrame(() => this._hostElement.classList.add(OPENING_CLASS, OPEN_CLASS));
117 this._waitForAnimationToComplete(this._enterAnimationDuration, this._finishDialogOpen);
118 } else {
119 this._hostElement.classList.add(OPEN_CLASS);
120 // Note: We could immediately finish the dialog opening here with noop animations,
121 // but we defer until next tick so that consumers can subscribe to `afterOpened`.
122 // Executing this immediately would mean that `afterOpened` emits synchronously
123 // on `dialog.open` before the consumer had a change to subscribe to `afterOpened`.

Callers

nothing calls this directly

Calls 4

_openAnimationDoneMethod · 0.95
_animationsDisabledFunction · 0.90
parseCssTimeFunction · 0.85

Tested by

no test coverage detected