@@ -10,7 +10,9 @@ import {FocusTrap, FocusTrapFactory, FocusMonitor, FocusOrigin} from '@angular/c
1010import { Directionality } from '@angular/cdk/bidi' ;
1111import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1212import { ESCAPE } from '@angular/cdk/keycodes' ;
13+ import { Platform } from '@angular/cdk/platform' ;
1314import {
15+ AfterContentChecked ,
1416 AfterContentInit ,
1517 ChangeDetectionStrategy ,
1618 ChangeDetectorRef ,
@@ -139,7 +141,7 @@ export class MatDrawerContent implements AfterContentInit {
139141 encapsulation : ViewEncapsulation . None ,
140142 preserveWhitespaces : false ,
141143} )
142- export class MatDrawer implements AfterContentInit , OnDestroy {
144+ export class MatDrawer implements AfterContentInit , AfterContentChecked , OnDestroy {
143145 private _focusTrap : FocusTrap ;
144146 private _elementFocusedBeforeDrawerWasOpened : HTMLElement | null = null ;
145147
@@ -257,6 +259,7 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
257259 constructor ( private _elementRef : ElementRef ,
258260 private _focusTrapFactory : FocusTrapFactory ,
259261 private _focusMonitor : FocusMonitor ,
262+ private _platform : Platform ,
260263 @Optional ( ) @Inject ( DOCUMENT ) private _doc : any ) {
261264 this . openedChange . subscribe ( ( opened : boolean ) => {
262265 if ( opened ) {
@@ -295,7 +298,16 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
295298 ngAfterContentInit ( ) {
296299 this . _focusTrap = this . _focusTrapFactory . create ( this . _elementRef . nativeElement ) ;
297300 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+ }
299311 }
300312
301313 ngOnDestroy ( ) {
0 commit comments