@@ -10,7 +10,9 @@ import {FocusTrap, FocusTrapFactory, FocusMonitor, FocusOrigin} from '@angular/c
10
10
import { Directionality } from '@angular/cdk/bidi' ;
11
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12
12
import { ESCAPE } from '@angular/cdk/keycodes' ;
13
+ import { Platform } from '@angular/cdk/platform' ;
13
14
import {
15
+ AfterContentChecked ,
14
16
AfterContentInit ,
15
17
ChangeDetectionStrategy ,
16
18
ChangeDetectorRef ,
@@ -139,7 +141,7 @@ export class MatDrawerContent implements AfterContentInit {
139
141
encapsulation : ViewEncapsulation . None ,
140
142
preserveWhitespaces : false ,
141
143
} )
142
- export class MatDrawer implements AfterContentInit , OnDestroy {
144
+ export class MatDrawer implements AfterContentInit , AfterContentChecked , OnDestroy {
143
145
private _focusTrap : FocusTrap ;
144
146
private _elementFocusedBeforeDrawerWasOpened : HTMLElement | null = null ;
145
147
@@ -257,6 +259,7 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
257
259
constructor ( private _elementRef : ElementRef ,
258
260
private _focusTrapFactory : FocusTrapFactory ,
259
261
private _focusMonitor : FocusMonitor ,
262
+ private _platform : Platform ,
260
263
@Optional ( ) @Inject ( DOCUMENT ) private _doc : any ) {
261
264
this . openedChange . subscribe ( ( opened : boolean ) => {
262
265
if ( opened ) {
@@ -295,7 +298,16 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
295
298
ngAfterContentInit ( ) {
296
299
this . _focusTrap = this . _focusTrapFactory . create ( this . _elementRef . nativeElement ) ;
297
300
this . _focusTrap . enabled = this . _isFocusTrapEnabled ;
298
- this . _enableAnimations = true ;
301
+ }
302
+
303
+ ngAfterContentChecked ( ) {
304
+ // Enable the animations after the lifecycle hooks have run, in order to avoid animating
305
+ // drawers that are open by default. When we're on the server, we shouldn't enable the
306
+ // animations, because we don't want the drawer to animate the first time the user sees
307
+ // the page.
308
+ if ( this . _platform . isBrowser ) {
309
+ this . _enableAnimations = true ;
310
+ }
299
311
}
300
312
301
313
ngOnDestroy ( ) {
0 commit comments