@@ -10,6 +10,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
1010import { By } from '@angular/platform-browser' ;
1111import { 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' ;
@@ -520,6 +521,27 @@ describe('MatDrawerContainer', () => {
520521 expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
521522 } ) ) ;
522523
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+
523545 it ( 'should not animate when the sidenav is open on load ' , fakeAsync ( ( ) => {
524546 const fixture = TestBed . createComponent ( DrawerSetToOpenedTrue ) ;
525547
@@ -696,14 +718,15 @@ class DrawerDelayed {
696718
697719@Component ( {
698720 template : `
699- <mat-drawer-container>
721+ <mat-drawer-container [dir]="direction" >
700722 <mat-drawer *ngIf="renderDrawer" [mode]="mode" style="width:100px"></mat-drawer>
701723 </mat-drawer-container>` ,
702724} )
703725class DrawerContainerStateChangesTestApp {
704726 @ViewChild ( MatDrawer ) drawer : MatDrawer ;
705727 @ViewChild ( MatDrawerContainer ) drawerContainer : MatDrawerContainer ;
706728
729+ direction : Direction = 'ltr' ;
707730 mode = 'side' ;
708731 renderDrawer = true ;
709732}
0 commit comments