@@ -23,6 +23,8 @@ import {
23
23
OnDestroy ,
24
24
Inject ,
25
25
ChangeDetectorRef ,
26
+ OnChanges ,
27
+ SimpleChanges ,
26
28
} from '@angular/core' ;
27
29
import { animate , state , style , transition , trigger , AnimationEvent } from '@angular/animations' ;
28
30
import { Directionality , coerceBooleanProperty } from '../core' ;
@@ -31,7 +33,7 @@ import {ESCAPE} from '../core/keyboard/keycodes';
31
33
import { first , takeUntil , startWith } from '../core/rxjs/index' ;
32
34
import { DOCUMENT } from '@angular/platform-browser' ;
33
35
import { merge } from 'rxjs/observable/merge' ;
34
- import { Subscription } from 'rxjs/Subscription ' ;
36
+ import { Subject } from 'rxjs/Subject ' ;
35
37
36
38
37
39
/** Throws an exception when two MdDrawer are matching the same position. */
@@ -90,7 +92,7 @@ export class MdDrawerToggleResult {
90
92
changeDetection : ChangeDetectionStrategy . OnPush ,
91
93
encapsulation : ViewEncapsulation . None ,
92
94
} )
93
- export class MdDrawer implements AfterContentInit , OnDestroy {
95
+ export class MdDrawer implements AfterContentInit , OnDestroy , OnChanges {
94
96
private _focusTrap : FocusTrap ;
95
97
private _elementFocusedBeforeDrawerWasOpened : HTMLElement | null = null ;
96
98
@@ -153,6 +155,9 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
153
155
/** Event emitted when the drawer's position changes. */
154
156
@Output ( 'positionChanged' ) onPositionChanged = new EventEmitter < void > ( ) ;
155
157
158
+ /** Event emitted when the drawer's mode changes. */
159
+ @Output ( 'modeChanged' ) onModeChanged = new EventEmitter < void > ( ) ;
160
+
156
161
/** @deprecated */
157
162
@Output ( 'align-changed' ) onAlignChanged = new EventEmitter < void > ( ) ;
158
163
@@ -206,6 +211,12 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
206
211
}
207
212
}
208
213
214
+ ngOnChanges ( changes : SimpleChanges ) {
215
+ if ( changes . mode ) {
216
+ this . onModeChanged . emit ( ) ;
217
+ }
218
+ }
219
+
209
220
/**
210
221
* Whether the drawer is opened. We overload this because we trigger an event when it
211
222
* starts or end.
@@ -339,8 +350,8 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
339
350
private _left : MdDrawer | null ;
340
351
private _right : MdDrawer | null ;
341
352
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 > ( ) ;
344
355
345
356
/** Inline styles to be applied to the container. */
346
357
_styles : { marginLeft : string ; marginRight : string ; transform : string ; } ;
@@ -351,22 +362,35 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
351
362
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
352
363
// properties to point to the proper start/end.
353
364
if ( _dir != null ) {
354
- this . _dirChangeSubscription = _dir . change . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
365
+
366
+ takeUntil . call ( _dir . change , this . _onDestroy ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
355
367
}
356
368
}
357
369
358
370
ngAfterContentInit ( ) {
359
371
startWith . call ( this . _drawers . changes , null ) . subscribe ( ( ) => {
360
372
this . _validateDrawers ( ) ;
373
+
361
374
this . _drawers . forEach ( ( drawer : MdDrawer ) => {
362
375
this . _watchDrawerToggle ( drawer ) ;
363
376
this . _watchDrawerPosition ( drawer ) ;
377
+ this . _watchDrawerMode ( drawer ) ;
364
378
} ) ;
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 ( ) ;
365
388
} ) ;
366
389
}
367
390
368
391
ngOnDestroy ( ) {
369
- this . _dirChangeSubscription . unsubscribe ( ) ;
392
+ this . _onDestroy . next ( ) ;
393
+ this . _onDestroy . complete ( ) ;
370
394
}
371
395
372
396
/** Calls `open` of both start and end drawers */
@@ -416,6 +440,14 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
416
440
} ) ;
417
441
}
418
442
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
+
419
451
/** Toggles the 'mat-drawer-opened' class on the main 'md-drawer-container' element. */
420
452
private _setContainerClass ( isAdd : boolean ) : void {
421
453
if ( isAdd ) {
0 commit comments