@@ -65,7 +65,6 @@ export class MdSidenavToggleResult {
65
65
'[class.mat-sidenav-over]' : '_modeOver' ,
66
66
'[class.mat-sidenav-push]' : '_modePush' ,
67
67
'[class.mat-sidenav-side]' : '_modeSide' ,
68
- '[class.mat-sidenav-invalid]' : '!valid' ,
69
68
'tabIndex' : '-1'
70
69
} ,
71
70
changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -77,19 +76,6 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
77
76
/** Alignment of the sidenav (direction neutral); whether 'start' or 'end'. */
78
77
private _align : 'start' | 'end' = 'start' ;
79
78
80
- /** Whether this md-sidenav is part of a valid md-sidenav-container configuration. */
81
- get valid ( ) { return this . _valid ; }
82
- set valid ( value ) {
83
- value = coerceBooleanProperty ( value ) ;
84
- // When the drawers are not in a valid configuration we close them all until they are in a valid
85
- // configuration again.
86
- if ( ! value ) {
87
- this . close ( ) ;
88
- }
89
- this . _valid = value ;
90
- }
91
- private _valid = true ;
92
-
93
79
/** Direction which the sidenav is aligned in. */
94
80
@Input ( )
95
81
get align ( ) { return this . _align ; }
@@ -221,10 +207,6 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
221
207
* @returns Resolves with the result of whether the sidenav was opened or closed.
222
208
*/
223
209
toggle ( isOpen : boolean = ! this . opened ) : Promise < MdSidenavToggleResult > {
224
- if ( ! this . valid ) {
225
- return Promise . resolve ( new MdSidenavToggleResult ( isOpen ? 'open' : 'close' , true ) ) ;
226
- }
227
-
228
210
// Shortcut it if we're already opened.
229
211
if ( isOpen === this . opened ) {
230
212
return this . _toggleAnimationPromise ||
@@ -410,25 +392,20 @@ export class MdSidenavContainer implements AfterContentInit {
410
392
* changes.
411
393
*/
412
394
private _watchSidenavAlign ( sidenav : MdSidenav ) : void {
413
- if ( ! sidenav ) { return ; }
414
- sidenav . onAlignChanged . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
395
+ if ( ! sidenav ) {
396
+ return ;
397
+ }
398
+ // NOTE: We need to wait for the microtask queue to be empty before validating,
399
+ // since both drawers may be swapping sides at the same time.
400
+ sidenav . onAlignChanged . subscribe ( ( ) =>
401
+ this . _ngZone . onMicrotaskEmpty . first ( ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ) ;
415
402
}
416
403
417
404
/** Toggles the 'mat-sidenav-opened' class on the main 'md-sidenav-container' element. */
418
405
private _setContainerClass ( sidenav : MdSidenav , bool : boolean ) : void {
419
406
this . _renderer . setElementClass ( this . _element . nativeElement , 'mat-sidenav-opened' , bool ) ;
420
407
}
421
408
422
- /** Sets the valid state of the drawers. */
423
- private _setDrawersValid ( valid : boolean ) {
424
- this . _sidenavs . forEach ( ( sidenav ) => {
425
- sidenav . valid = valid ;
426
- } ) ;
427
- if ( ! valid ) {
428
- this . _start = this . _end = this . _left = this . _right = null ;
429
- }
430
- }
431
-
432
409
/** Validate the state of the sidenav children components. */
433
410
private _validateDrawers ( ) {
434
411
this . _start = this . _end = null ;
@@ -439,14 +416,12 @@ export class MdSidenavContainer implements AfterContentInit {
439
416
for ( let sidenav of this . _sidenavs . toArray ( ) ) {
440
417
if ( sidenav . align == 'end' ) {
441
418
if ( this . _end != null ) {
442
- this . _setDrawersValid ( false ) ;
443
- return ;
419
+ throw new MdDuplicatedSidenavError ( 'end' ) ;
444
420
}
445
421
this . _end = sidenav ;
446
422
} else {
447
423
if ( this . _start != null ) {
448
- this . _setDrawersValid ( false ) ;
449
- return ;
424
+ throw new MdDuplicatedSidenavError ( 'start' ) ;
450
425
}
451
426
this . _start = sidenav ;
452
427
}
@@ -462,8 +437,6 @@ export class MdSidenavContainer implements AfterContentInit {
462
437
this . _left = this . _end ;
463
438
this . _right = this . _start ;
464
439
}
465
-
466
- this . _setDrawersValid ( true ) ;
467
440
}
468
441
469
442
_onBackdropClicked ( ) {
0 commit comments