@@ -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' ;
@@ -32,6 +34,7 @@ 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
36
import { Subscription } from 'rxjs/Subscription' ;
37
+ import { Subject } from 'rxjs/Subject' ;
35
38
36
39
37
40
/** Throws an exception when two MdDrawer are matching the same position. */
@@ -90,7 +93,7 @@ export class MdDrawerToggleResult {
90
93
changeDetection : ChangeDetectionStrategy . OnPush ,
91
94
encapsulation : ViewEncapsulation . None ,
92
95
} )
93
- export class MdDrawer implements AfterContentInit , OnDestroy {
96
+ export class MdDrawer implements AfterContentInit , OnDestroy , OnChanges {
94
97
private _focusTrap : FocusTrap ;
95
98
private _elementFocusedBeforeDrawerWasOpened : HTMLElement | null = null ;
96
99
@@ -153,6 +156,9 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
153
156
/** Event emitted when the drawer's position changes. */
154
157
@Output ( 'positionChanged' ) onPositionChanged = new EventEmitter < void > ( ) ;
155
158
159
+ /** Event emitted when the drawer's mode changes. */
160
+ @Output ( 'modeChanged' ) onModeChanged = new EventEmitter < void > ( ) ;
161
+
156
162
/** @deprecated */
157
163
@Output ( 'align-changed' ) onAlignChanged = new EventEmitter < void > ( ) ;
158
164
@@ -206,6 +212,12 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
206
212
}
207
213
}
208
214
215
+ ngOnChanges ( changes : SimpleChanges ) {
216
+ if ( changes . mode ) {
217
+ this . onModeChanged . emit ( ) ;
218
+ }
219
+ }
220
+
209
221
/**
210
222
* Whether the drawer is opened. We overload this because we trigger an event when it
211
223
* starts or end.
@@ -339,8 +351,8 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
339
351
private _left : MdDrawer | null ;
340
352
private _right : MdDrawer | null ;
341
353
342
- /** Subscription to the Directionality change EventEmitter . */
343
- private _dirChangeSubscription = Subscription . EMPTY ;
354
+ /** Emits when the component is destroyed . */
355
+ private _onDestroy = new Subject < void > ( ) ;
344
356
345
357
/** Inline styles to be applied to the container. */
346
358
_styles : { marginLeft : string ; marginRight : string ; transform : string ; } ;
@@ -351,22 +363,35 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
351
363
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
352
364
// properties to point to the proper start/end.
353
365
if ( _dir != null ) {
354
- this . _dirChangeSubscription = _dir . change . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
366
+
367
+ takeUntil . call ( _dir . change , this . _onDestroy ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
355
368
}
356
369
}
357
370
358
371
ngAfterContentInit ( ) {
359
372
startWith . call ( this . _drawers . changes , null ) . subscribe ( ( ) => {
360
373
this . _validateDrawers ( ) ;
374
+
361
375
this . _drawers . forEach ( ( drawer : MdDrawer ) => {
362
376
this . _watchDrawerToggle ( drawer ) ;
363
377
this . _watchDrawerPosition ( drawer ) ;
378
+ this . _watchDrawerMode ( drawer ) ;
364
379
} ) ;
380
+
381
+ if ( ! this . _drawers . length ||
382
+ this . _isDrawerOpen ( this . _start ) ||
383
+ this . _isDrawerOpen ( this . _end )
384
+ ) {
385
+ this . _updateStyles ( ) ;
386
+ }
387
+
388
+ this . _changeDetectorRef . markForCheck ( ) ;
365
389
} ) ;
366
390
}
367
391
368
392
ngOnDestroy ( ) {
369
- this . _dirChangeSubscription . unsubscribe ( ) ;
393
+ this . _onDestroy . next ( ) ;
394
+ this . _onDestroy . complete ( ) ;
370
395
}
371
396
372
397
/** Calls `open` of both start and end drawers */
@@ -416,6 +441,14 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
416
441
} ) ;
417
442
}
418
443
444
+ private _watchDrawerMode ( drawer : MdDrawer ) : void {
445
+ takeUntil . call ( drawer . onModeChanged , merge ( this . _drawers . changes , this . _onDestroy ) )
446
+ . subscribe ( ( ) => {
447
+ this . _updateStyles ( ) ;
448
+ this . _changeDetectorRef . markForCheck ( ) ;
449
+ } ) ;
450
+ }
451
+
419
452
/** Toggles the 'mat-drawer-opened' class on the main 'md-drawer-container' element. */
420
453
private _setContainerClass ( isAdd : boolean ) : void {
421
454
if ( isAdd ) {
0 commit comments