@@ -10,6 +10,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
10
10
import { By } from '@angular/platform-browser' ;
11
11
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
12
12
import { MatDrawer , MatSidenavModule , MatDrawerContainer } from './index' ;
13
+ import { Direction } from '@angular/cdk/bidi' ;
13
14
import { A11yModule } from '@angular/cdk/a11y' ;
14
15
import { PlatformModule } from '@angular/cdk/platform' ;
15
16
import { ESCAPE } from '@angular/cdk/keycodes' ;
@@ -573,6 +574,27 @@ describe('MatDrawerContainer', () => {
573
574
expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
574
575
} ) ) ;
575
576
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
+
576
598
it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
577
599
const fixture = TestBed . createComponent ( DrawerSetToOpenedTrue ) ;
578
600
@@ -760,14 +782,15 @@ class DrawerDelayed {
760
782
761
783
@Component ( {
762
784
template : `
763
- <mat-drawer-container>
785
+ <mat-drawer-container [dir]="direction" >
764
786
<mat-drawer *ngIf="renderDrawer" [mode]="mode" style="width:100px"></mat-drawer>
765
787
</mat-drawer-container>` ,
766
788
} )
767
789
class DrawerContainerStateChangesTestApp {
768
790
@ViewChild ( MatDrawer ) drawer : MatDrawer ;
769
791
@ViewChild ( MatDrawerContainer ) drawerContainer : MatDrawerContainer ;
770
792
793
+ direction : Direction = 'ltr' ;
771
794
mode = 'side' ;
772
795
renderDrawer = true ;
773
796
}
0 commit comments