@@ -323,7 +323,11 @@ describe('MatDrawerContainer', () => {
323
323
beforeEach ( async ( ( ) => {
324
324
TestBed . configureTestingModule ( {
325
325
imports : [ MatSidenavModule , A11yModule , PlatformModule , NoopAnimationsModule ] ,
326
- declarations : [ DrawerContainerTwoDrawerTestApp , DrawerDelayed ] ,
326
+ declarations : [
327
+ DrawerContainerTwoDrawerTestApp ,
328
+ DrawerDelayed ,
329
+ DrawerContainerStateChangesTestApp ,
330
+ ] ,
327
331
} ) ;
328
332
329
333
TestBed . compileComponents ( ) ;
@@ -372,6 +376,47 @@ describe('MatDrawerContainer', () => {
372
376
373
377
expect ( parseInt ( contentElement . style . marginLeft ) ) . toBeGreaterThan ( 0 ) ;
374
378
} ) ) ;
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
+
375
420
} ) ;
376
421
377
422
@@ -485,3 +530,19 @@ class DrawerDelayed {
485
530
@ViewChild ( MatDrawer ) drawer : MatDrawer ;
486
531
showDrawer = false ;
487
532
}
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