@@ -23,6 +23,8 @@ import {
2323 OnDestroy ,
2424 Inject ,
2525 ChangeDetectorRef ,
26+ OnChanges ,
27+ SimpleChanges ,
2628} from '@angular/core' ;
2729import { animate , state , style , transition , trigger , AnimationEvent } from '@angular/animations' ;
2830import { Directionality , coerceBooleanProperty } from '../core' ;
@@ -31,7 +33,7 @@ import {ESCAPE} from '../core/keyboard/keycodes';
3133import { first , takeUntil , startWith } from '../core/rxjs/index' ;
3234import { DOCUMENT } from '@angular/platform-browser' ;
3335import { merge } from 'rxjs/observable/merge' ;
34- import { Subscription } from 'rxjs/Subscription ' ;
36+ import { Subject } from 'rxjs/Subject ' ;
3537
3638
3739/** Throws an exception when two MdDrawer are matching the same position. */
@@ -90,7 +92,7 @@ export class MdDrawerToggleResult {
9092 changeDetection : ChangeDetectionStrategy . OnPush ,
9193 encapsulation : ViewEncapsulation . None ,
9294} )
93- export class MdDrawer implements AfterContentInit , OnDestroy {
95+ export class MdDrawer implements AfterContentInit , OnDestroy , OnChanges {
9496 private _focusTrap : FocusTrap ;
9597 private _elementFocusedBeforeDrawerWasOpened : HTMLElement | null = null ;
9698
@@ -153,6 +155,9 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
153155 /** Event emitted when the drawer's position changes. */
154156 @Output ( 'positionChanged' ) onPositionChanged = new EventEmitter < void > ( ) ;
155157
158+ /** Event emitted when the drawer's mode changes. */
159+ @Output ( 'modeChanged' ) onModeChanged = new EventEmitter < void > ( ) ;
160+
156161 /** @deprecated */
157162 @Output ( 'align-changed' ) onAlignChanged = new EventEmitter < void > ( ) ;
158163
@@ -206,6 +211,12 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
206211 }
207212 }
208213
214+ ngOnChanges ( changes : SimpleChanges ) {
215+ if ( changes . mode ) {
216+ this . onModeChanged . emit ( ) ;
217+ }
218+ }
219+
209220 /**
210221 * Whether the drawer is opened. We overload this because we trigger an event when it
211222 * starts or end.
@@ -339,8 +350,8 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
339350 private _left : MdDrawer | null ;
340351 private _right : MdDrawer | null ;
341352
342- /** Subscription to the Directionality change EventEmitter . */
343- private _dirChangeSubscription = Subscription . EMPTY ;
353+ /** Emits when the component is destroyed . */
354+ private _onDestroy = new Subject < void > ( ) ;
344355
345356 /** Inline styles to be applied to the container. */
346357 _styles : { marginLeft : string ; marginRight : string ; transform : string ; } ;
@@ -351,22 +362,35 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
351362 // If a `Dir` directive exists up the tree, listen direction changes and update the left/right
352363 // properties to point to the proper start/end.
353364 if ( _dir != null ) {
354- this . _dirChangeSubscription = _dir . change . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
365+
366+ takeUntil . call ( _dir . change , this . _onDestroy ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
355367 }
356368 }
357369
358370 ngAfterContentInit ( ) {
359371 startWith . call ( this . _drawers . changes , null ) . subscribe ( ( ) => {
360372 this . _validateDrawers ( ) ;
373+
361374 this . _drawers . forEach ( ( drawer : MdDrawer ) => {
362375 this . _watchDrawerToggle ( drawer ) ;
363376 this . _watchDrawerPosition ( drawer ) ;
377+ this . _watchDrawerMode ( drawer ) ;
364378 } ) ;
379+
380+ if ( ! this . _drawers . length ||
381+ this . _isDrawerOpen ( this . _start ) ||
382+ this . _isDrawerOpen ( this . _end )
383+ ) {
384+ this . _updateStyles ( ) ;
385+ }
386+
387+ this . _changeDetectorRef . markForCheck ( ) ;
365388 } ) ;
366389 }
367390
368391 ngOnDestroy ( ) {
369- this . _dirChangeSubscription . unsubscribe ( ) ;
392+ this . _onDestroy . next ( ) ;
393+ this . _onDestroy . complete ( ) ;
370394 }
371395
372396 /** Calls `open` of both start and end drawers */
@@ -416,6 +440,14 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
416440 } ) ;
417441 }
418442
443+ private _watchDrawerMode ( drawer : MdDrawer ) : void {
444+ takeUntil . call ( drawer . onModeChanged , merge ( this . _drawers . changes , this . _onDestroy ) )
445+ . subscribe ( ( ) => {
446+ this . _updateStyles ( ) ;
447+ this . _changeDetectorRef . markForCheck ( ) ;
448+ } ) ;
449+ }
450+
419451 /** Toggles the 'mat-drawer-opened' class on the main 'md-drawer-container' element. */
420452 private _setContainerClass ( isAdd : boolean ) : void {
421453 if ( isAdd ) {
0 commit comments