@@ -10,6 +10,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
1010import { By } from '@angular/platform-browser' ;
1111import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
1212import { MatDrawer , MatSidenavModule , MatDrawerContainer } from './index' ;
13+ import { Direction } from '@angular/cdk/bidi' ;
1314import { A11yModule } from '@angular/cdk/a11y' ;
1415import { PlatformModule } from '@angular/cdk/platform' ;
1516import { ESCAPE } from '@angular/cdk/keycodes' ;
@@ -573,6 +574,27 @@ describe('MatDrawerContainer', () => {
573574 expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
574575 } ) ) ;
575576
577+ it ( 'should recalculate the margin if the direction has changed' , fakeAsync ( ( ) => {
578+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
579+
580+ fixture . detectChanges ( ) ;
581+ fixture . componentInstance . drawer . open ( ) ;
582+ fixture . detectChanges ( ) ;
583+ tick ( ) ;
584+ fixture . detectChanges ( ) ;
585+
586+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
587+ const margin = parseInt ( contentElement . style . marginLeft ) ;
588+
589+ expect ( margin ) . toBeGreaterThan ( 0 ) ;
590+
591+ fixture . componentInstance . direction = 'rtl' ;
592+ fixture . detectChanges ( ) ;
593+
594+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBe ( 0 ) ;
595+ expect ( parseInt ( contentElement . style . marginRight ) ) . toBe ( margin ) ;
596+ } ) ) ;
597+
576598 it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
577599 const fixture = TestBed . createComponent ( DrawerSetToOpenedTrue ) ;
578600
@@ -760,14 +782,15 @@ class DrawerDelayed {
760782
761783@Component ( {
762784 template : `
763- <mat-drawer-container>
785+ <mat-drawer-container [dir]="direction" >
764786 <mat-drawer *ngIf="renderDrawer" [mode]="mode" style="width:100px"></mat-drawer>
765787 </mat-drawer-container>` ,
766788} )
767789class DrawerContainerStateChangesTestApp {
768790 @ViewChild ( MatDrawer ) drawer : MatDrawer ;
769791 @ViewChild ( MatDrawerContainer ) drawerContainer : MatDrawerContainer ;
770792
793+ direction : Direction = 'ltr' ;
771794 mode = 'side' ;
772795 renderDrawer = true ;
773796}
0 commit comments