@@ -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 {
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 ; }
@@ -208,10 +194,6 @@ export class MdSidenav implements AfterContentInit {
208
194
* @returns Resolves with the result of whether the sidenav was opened or closed.
209
195
*/
210
196
toggle ( isOpen : boolean = ! this . opened ) : Promise < MdSidenavToggleResult > {
211
- if ( ! this . valid ) {
212
- return Promise . resolve ( new MdSidenavToggleResult ( isOpen ? 'open' : 'close' , true ) ) ;
213
- }
214
-
215
197
// Shortcut it if we're already opened.
216
198
if ( isOpen === this . opened ) {
217
199
return this . _toggleAnimationPromise ||
@@ -393,25 +375,20 @@ export class MdSidenavContainer implements AfterContentInit {
393
375
* changes.
394
376
*/
395
377
private _watchSidenavAlign ( sidenav : MdSidenav ) : void {
396
- if ( ! sidenav ) { return ; }
397
- sidenav . onAlignChanged . subscribe ( ( ) => this . _validateDrawers ( ) ) ;
378
+ if ( ! sidenav ) {
379
+ return ;
380
+ }
381
+ // NOTE: We need to wait for the microtask queue to be empty before validating,
382
+ // since both drawers may be swapping sides at the same time.
383
+ sidenav . onAlignChanged . subscribe ( ( ) =>
384
+ this . _ngZone . onMicrotaskEmpty . first ( ) . subscribe ( ( ) => this . _validateDrawers ( ) ) ) ;
398
385
}
399
386
400
387
/** Toggles the 'mat-sidenav-opened' class on the main 'md-sidenav-container' element. */
401
388
private _setContainerClass ( sidenav : MdSidenav , bool : boolean ) : void {
402
389
this . _renderer . setElementClass ( this . _element . nativeElement , 'mat-sidenav-opened' , bool ) ;
403
390
}
404
391
405
- /** Sets the valid state of the drawers. */
406
- private _setDrawersValid ( valid : boolean ) {
407
- this . _sidenavs . forEach ( ( sidenav ) => {
408
- sidenav . valid = valid ;
409
- } ) ;
410
- if ( ! valid ) {
411
- this . _start = this . _end = this . _left = this . _right = null ;
412
- }
413
- }
414
-
415
392
/** Validate the state of the sidenav children components. */
416
393
private _validateDrawers ( ) {
417
394
this . _start = this . _end = null ;
@@ -422,14 +399,12 @@ export class MdSidenavContainer implements AfterContentInit {
422
399
for ( let sidenav of this . _sidenavs . toArray ( ) ) {
423
400
if ( sidenav . align == 'end' ) {
424
401
if ( this . _end != null ) {
425
- this . _setDrawersValid ( false ) ;
426
- return ;
402
+ throw new MdDuplicatedSidenavError ( 'end' ) ;
427
403
}
428
404
this . _end = sidenav ;
429
405
} else {
430
406
if ( this . _start != null ) {
431
- this . _setDrawersValid ( false ) ;
432
- return ;
407
+ throw new MdDuplicatedSidenavError ( 'start' ) ;
433
408
}
434
409
this . _start = sidenav ;
435
410
}
@@ -445,8 +420,6 @@ export class MdSidenavContainer implements AfterContentInit {
445
420
this . _left = this . _end ;
446
421
this . _right = this . _start ;
447
422
}
448
-
449
- this . _setDrawersValid ( true ) ;
450
423
}
451
424
452
425
_onBackdropClicked ( ) {
0 commit comments