@@ -24,6 +24,7 @@ import {MatDialogConfig} from './dialog-config';
24
24
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
25
25
import { cssClasses , numbers } from '@material/dialog' ;
26
26
import { CdkDialogContainer } from '@angular/cdk/dialog' ;
27
+ import { coerceNumberProperty } from '@angular/cdk/coercion' ;
27
28
28
29
/** Event that captures the state of dialog container animations. */
29
30
interface LegacyDialogAnimationEvent {
@@ -85,6 +86,22 @@ export abstract class _MatDialogContainerBase extends CdkDialogContainer<MatDial
85
86
}
86
87
}
87
88
89
+ const TRANSITION_DURATION_PROPERTY = '--mat-dialog-transition-duration' ;
90
+
91
+ function parseCssTime ( time : string | undefined ) : number | null {
92
+ if ( time == null ) {
93
+ return null ;
94
+ }
95
+ if ( time . endsWith ( 'ms' ) ) {
96
+ return coerceNumberProperty ( time . substring ( 0 , time . length - 2 ) ) ;
97
+ } else if ( time . endsWith ( 's' ) ) {
98
+ return coerceNumberProperty ( time . substring ( 0 , time . length - 1 ) ) ;
99
+ } else if ( time === '0' ) {
100
+ return 0 ;
101
+ }
102
+ return null ; // anything else is invalid.
103
+ }
104
+
88
105
/**
89
106
* Internal component that wraps user-provided dialog content in a MDC dialog.
90
107
* @docs -private
@@ -117,11 +134,11 @@ export class MatDialogContainer extends _MatDialogContainerBase implements OnDes
117
134
private _hostElement : HTMLElement = this . _elementRef . nativeElement ;
118
135
/** Duration of the dialog open animation. */
119
136
private _openAnimationDuration = this . _animationsEnabled
120
- ? numbers . DIALOG_ANIMATION_OPEN_TIME_MS
137
+ ? parseCssTime ( this . _config . enterAnimationDuration ) ?? numbers . DIALOG_ANIMATION_OPEN_TIME_MS
121
138
: 0 ;
122
139
/** Duration of the dialog close animation. */
123
140
private _closeAnimationDuration = this . _animationsEnabled
124
- ? numbers . DIALOG_ANIMATION_CLOSE_TIME_MS
141
+ ? parseCssTime ( this . _config . exitAnimationDuration ) ?? numbers . DIALOG_ANIMATION_CLOSE_TIME_MS
125
142
: 0 ;
126
143
/** Current timer for dialog animations. */
127
144
private _animationTimer : number | null = null ;
@@ -181,6 +198,10 @@ export class MatDialogContainer extends _MatDialogContainerBase implements OnDes
181
198
if ( this . _animationsEnabled ) {
182
199
// One would expect that the open class is added once the animation finished, but MDC
183
200
// uses the open class in combination with the opening class to start the animation.
201
+ this . _hostElement . style . setProperty (
202
+ TRANSITION_DURATION_PROPERTY ,
203
+ `${ this . _openAnimationDuration } ms` ,
204
+ ) ;
184
205
this . _hostElement . classList . add ( cssClasses . OPENING ) ;
185
206
this . _hostElement . classList . add ( cssClasses . OPEN ) ;
186
207
this . _waitForAnimationToComplete ( this . _openAnimationDuration , this . _finishDialogOpen ) ;
@@ -203,6 +224,10 @@ export class MatDialogContainer extends _MatDialogContainerBase implements OnDes
203
224
this . _hostElement . classList . remove ( cssClasses . OPEN ) ;
204
225
205
226
if ( this . _animationsEnabled ) {
227
+ this . _hostElement . style . setProperty (
228
+ TRANSITION_DURATION_PROPERTY ,
229
+ `${ this . _openAnimationDuration } ms` ,
230
+ ) ;
206
231
this . _hostElement . classList . add ( cssClasses . CLOSING ) ;
207
232
this . _waitForAnimationToComplete ( this . _closeAnimationDuration , this . _finishDialogClose ) ;
208
233
} else {
0 commit comments