@@ -323,7 +323,11 @@ describe('MatDrawerContainer', () => {
323323 beforeEach ( async ( ( ) => {
324324 TestBed . configureTestingModule ( {
325325 imports : [ MatSidenavModule , A11yModule , PlatformModule , NoopAnimationsModule ] ,
326- declarations : [ DrawerContainerTwoDrawerTestApp , DrawerDelayed ] ,
326+ declarations : [
327+ DrawerContainerTwoDrawerTestApp ,
328+ DrawerDelayed ,
329+ DrawerContainerStateChangesTestApp ,
330+ ] ,
327331 } ) ;
328332
329333 TestBed . compileComponents ( ) ;
@@ -372,6 +376,47 @@ describe('MatDrawerContainer', () => {
372376
373377 expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeGreaterThan ( 0 ) ;
374378 } ) ) ;
379+
380+ it ( 'should recalculate the margin if a drawer is destroyed' , fakeAsync ( ( ) => {
381+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
382+
383+ fixture . detectChanges ( ) ;
384+ fixture . componentInstance . drawer . open ( ) ;
385+ fixture . detectChanges ( ) ;
386+ tick ( ) ;
387+ fixture . detectChanges ( ) ;
388+
389+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
390+ const initialMargin = parseInt ( contentElement . style . marginLeft ) ;
391+
392+ expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
393+
394+ fixture . componentInstance . renderDrawer = false ;
395+ fixture . detectChanges ( ) ;
396+
397+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
398+ } ) ) ;
399+
400+ it ( 'should recalculate the margin if the drawer mode is changed' , fakeAsync ( ( ) => {
401+ const fixture = TestBed . createComponent ( DrawerContainerStateChangesTestApp ) ;
402+
403+ fixture . detectChanges ( ) ;
404+ fixture . componentInstance . drawer . open ( ) ;
405+ fixture . detectChanges ( ) ;
406+ tick ( ) ;
407+ fixture . detectChanges ( ) ;
408+
409+ const contentElement = fixture . debugElement . nativeElement . querySelector ( '.mat-drawer-content' ) ;
410+ const initialMargin = parseInt ( contentElement . style . marginLeft ) ;
411+
412+ expect ( initialMargin ) . toBeGreaterThan ( 0 ) ;
413+
414+ fixture . componentInstance . mode = 'over' ;
415+ fixture . detectChanges ( ) ;
416+
417+ expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeLessThan ( initialMargin ) ;
418+ } ) ) ;
419+
375420} ) ;
376421
377422
@@ -485,3 +530,19 @@ class DrawerDelayed {
485530 @ViewChild ( MatDrawer ) drawer : MatDrawer ;
486531 showDrawer = false ;
487532}
533+
534+
535+ @Component ( {
536+ template : `
537+ <mat-drawer-container>
538+ <mat-drawer *ngIf="renderDrawer" [mode]="mode"></mat-drawer>
539+ </mat-drawer-container>` ,
540+ } )
541+ class DrawerContainerStateChangesTestApp {
542+ @ViewChild ( MatDrawer ) drawer : MatDrawer ;
543+ @ViewChild ( MatDrawerContainer ) drawerContainer : MatDrawerContainer ;
544+
545+ mode = 'side' ;
546+ renderDrawer = true ;
547+ }
548+
0 commit comments