@@ -10,6 +10,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
10
10
import { By } from '@angular/platform-browser' ;
11
11
import { 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' ;
@@ -520,6 +521,27 @@ describe('MatDrawerContainer', () => {
520
521
expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
521
522
} ) ) ;
522
523
524
+ it ( 'should recalculate the margin if the direction has changed' , fakeAsync ( ( ) => {
525
+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
526
+
527
+ fixture . detectChanges ( ) ;
528
+ fixture . componentInstance . drawer . open ( ) ;
529
+ fixture . detectChanges ( ) ;
530
+ tick ( ) ;
531
+ fixture . detectChanges ( ) ;
532
+
533
+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
534
+ const margin = parseInt ( contentElement . style . marginLeft ) ;
535
+
536
+ expect ( margin ) . toBeGreaterThan ( 0 ) ;
537
+
538
+ fixture . componentInstance . direction = 'rtl' ;
539
+ fixture . detectChanges ( ) ;
540
+
541
+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBe ( 0 ) ;
542
+ expect ( parseInt ( contentElement . style . marginRight ) ) . toBe ( margin ) ;
543
+ } ) ) ;
544
+
523
545
it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
524
546
const fixture = TestBed . createComponent ( DrawerSetToOpenedTrue ) ;
525
547
@@ -696,14 +718,15 @@ class DrawerDelayed {
696
718
697
719
@Component ( {
698
720
template : `
699
- <mat-drawer-container>
721
+ <mat-drawer-container [dir]="direction" >
700
722
<mat-drawer *ngIf="renderDrawer" [mode]="mode" style="width:100px"></mat-drawer>
701
723
</mat-drawer-container>` ,
702
724
} )
703
725
class DrawerContainerStateChangesTestApp {
704
726
@ViewChild ( MatDrawer ) drawer : MatDrawer ;
705
727
@ViewChild ( MatDrawerContainer ) drawerContainer : MatDrawerContainer ;
706
728
729
+ direction : Direction = 'ltr' ;
707
730
mode = 'side' ;
708
731
renderDrawer = true ;
709
732
}
0 commit comments