@@ -65,7 +65,6 @@ export class MdSidenavToggleResult {
6565 '[class.mat-sidenav-over]' : '_modeOver' ,
6666 '[class.mat-sidenav-push]' : '_modePush' ,
6767 '[class.mat-sidenav-side]' : '_modeSide' ,
68- '[class.mat-sidenav-invalid]' : '!valid' ,
6968 'tabIndex' : '-1'
7069 } ,
7170 changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -77,19 +76,6 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
7776 /** Alignment of the sidenav (direction neutral); whether 'start' or 'end'. */
7877 private _align : 'start' | 'end' = 'start' ;
7978
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-
9379 /** Direction which the sidenav is aligned in. */
9480 @Input ( )
9581 get align ( ) { return this . _align ; }
@@ -221,10 +207,6 @@ export class MdSidenav implements AfterContentInit, OnDestroy {
221207 * @returns Resolves with the result of whether the sidenav was opened or closed.
222208 */
223209 toggle ( isOpen : boolean = ! this . opened ) : Promise < MdSidenavToggleResult > {
224- if ( ! this . valid ) {
225- return Promise . resolve ( new MdSidenavToggleResult ( isOpen ? 'open' : 'close' , true ) ) ;
226- }
227-
228210 // Shortcut it if we're already opened.
229211 if ( isOpen === this . opened ) {
230212 return this . _toggleAnimationPromise ||
@@ -410,25 +392,20 @@ export class MdSidenavContainer implements AfterContentInit {
410392 * changes.
411393 */
412394 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 ( ) ) ) ;
415402 }
416403
417404 /** Toggles the 'mat-sidenav-opened' class on the main 'md-sidenav-container' element. */
418405 private _setContainerClass ( sidenav : MdSidenav , bool : boolean ) : void {
419406 this . _renderer . setElementClass ( this . _element . nativeElement , 'mat-sidenav-opened' , bool ) ;
420407 }
421408
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-
432409 /** Validate the state of the sidenav children components. */
433410 private _validateDrawers ( ) {
434411 this . _start = this . _end = null ;
@@ -439,14 +416,12 @@ export class MdSidenavContainer implements AfterContentInit {
439416 for ( let sidenav of this . _sidenavs . toArray ( ) ) {
440417 if ( sidenav . align == 'end' ) {
441418 if ( this . _end != null ) {
442- this . _setDrawersValid ( false ) ;
443- return ;
419+ throw new MdDuplicatedSidenavError ( 'end' ) ;
444420 }
445421 this . _end = sidenav ;
446422 } else {
447423 if ( this . _start != null ) {
448- this . _setDrawersValid ( false ) ;
449- return ;
424+ throw new MdDuplicatedSidenavError ( 'start' ) ;
450425 }
451426 this . _start = sidenav ;
452427 }
@@ -462,8 +437,6 @@ export class MdSidenavContainer implements AfterContentInit {
462437 this . _left = this . _end ;
463438 this . _right = this . _start ;
464439 }
465-
466- this . _setDrawersValid ( true ) ;
467440 }
468441
469442 _onBackdropClicked ( ) {
0 commit comments