@@ -541,15 +541,15 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
541
541
if ( _dir ) {
542
542
_dir . change . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( ( ) => {
543
543
this . _validateDrawers ( ) ;
544
- this . _updateContentMargins ( ) ;
544
+ this . updateContentMargins ( ) ;
545
545
} ) ;
546
546
}
547
547
548
548
// Since the minimum width of the sidenav depends on the viewport width,
549
549
// we need to recompute the margins if the viewport changes.
550
550
viewportRuler . change ( )
551
551
. pipe ( takeUntil ( this . _destroyed ) )
552
- . subscribe ( ( ) => this . _updateContentMargins ( ) ) ;
552
+ . subscribe ( ( ) => this . updateContentMargins ( ) ) ;
553
553
554
554
this . _autosize = defaultAutosize ;
555
555
}
@@ -567,7 +567,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
567
567
if ( ! this . _drawers . length ||
568
568
this . _isDrawerOpen ( this . _start ) ||
569
569
this . _isDrawerOpen ( this . _end ) ) {
570
- this . _updateContentMargins ( ) ;
570
+ this . updateContentMargins ( ) ;
571
571
}
572
572
573
573
this . _changeDetectorRef . markForCheck ( ) ;
@@ -576,7 +576,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
576
576
this . _doCheckSubject . pipe (
577
577
debounceTime ( 10 ) , // Arbitrary debounce time, less than a frame at 60fps
578
578
takeUntil ( this . _destroyed )
579
- ) . subscribe ( ( ) => this . _updateContentMargins ( ) ) ;
579
+ ) . subscribe ( ( ) => this . updateContentMargins ( ) ) ;
580
580
}
581
581
582
582
ngOnDestroy ( ) {
@@ -596,6 +596,56 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
596
596
this . _drawers . forEach ( drawer => drawer . close ( ) ) ;
597
597
}
598
598
599
+ /**
600
+ * Recalculates and updates the inline styles for the content. Note that this should be used
601
+ * sparingly, because it causes a reflow.
602
+ */
603
+ updateContentMargins ( ) {
604
+ // 1. For drawers in `over` mode, they don't affect the content.
605
+ // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
606
+ // left margin (for left drawer) or right margin (for right the drawer).
607
+ // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
608
+ // adding to the left or right margin and simultaneously subtracting the same amount of
609
+ // margin from the other side.
610
+ let left = 0 ;
611
+ let right = 0 ;
612
+
613
+ if ( this . _left && this . _left . opened ) {
614
+ if ( this . _left . mode == 'side' ) {
615
+ left += this . _left . _width ;
616
+ } else if ( this . _left . mode == 'push' ) {
617
+ const width = this . _left . _width ;
618
+ left += width ;
619
+ right -= width ;
620
+ }
621
+ }
622
+
623
+ if ( this . _right && this . _right . opened ) {
624
+ if ( this . _right . mode == 'side' ) {
625
+ right += this . _right . _width ;
626
+ } else if ( this . _right . mode == 'push' ) {
627
+ const width = this . _right . _width ;
628
+ right += width ;
629
+ left -= width ;
630
+ }
631
+ }
632
+
633
+ // If either `right` or `left` is zero, don't set a style to the element. This
634
+ // allows users to specify a custom size via CSS class in SSR scenarios where the
635
+ // measured widths will always be zero. Note that we reset to `null` here, rather
636
+ // than below, in order to ensure that the types in the `if` below are consistent.
637
+ left = left || null ! ;
638
+ right = right || null ! ;
639
+
640
+ if ( left !== this . _contentMargins . left || right !== this . _contentMargins . right ) {
641
+ this . _contentMargins = { left, right} ;
642
+
643
+ // Pull back into the NgZone since in some cases we could be outside. We need to be careful
644
+ // to do it only when something changed, otherwise we can end up hitting the zone too often.
645
+ this . _ngZone . run ( ( ) => this . _contentMarginChanges . next ( this . _contentMargins ) ) ;
646
+ }
647
+ }
648
+
599
649
ngDoCheck ( ) {
600
650
// If users opted into autosizing, do a check every change detection cycle.
601
651
if ( this . _autosize && this . _isPushed ( ) ) {
@@ -621,7 +671,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
621
671
this . _element . nativeElement . classList . add ( 'mat-drawer-transition' ) ;
622
672
}
623
673
624
- this . _updateContentMargins ( ) ;
674
+ this . updateContentMargins ( ) ;
625
675
this . _changeDetectorRef . markForCheck ( ) ;
626
676
} ) ;
627
677
@@ -653,7 +703,7 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
653
703
if ( drawer ) {
654
704
drawer . _modeChanged . pipe ( takeUntil ( merge ( this . _drawers . changes , this . _destroyed ) ) )
655
705
. subscribe ( ( ) => {
656
- this . _updateContentMargins ( ) ;
706
+ this . updateContentMargins ( ) ;
657
707
this . _changeDetectorRef . markForCheck ( ) ;
658
708
} ) ;
659
709
}
@@ -730,55 +780,4 @@ export class MatDrawerContainer implements AfterContentInit, DoCheck, OnDestroy
730
780
return drawer != null && drawer . opened ;
731
781
}
732
782
733
- /**
734
- * Recalculates and updates the inline styles for the content. Note that this should be used
735
- * sparingly, because it causes a reflow.
736
- */
737
- private _updateContentMargins ( ) {
738
- // 1. For drawers in `over` mode, they don't affect the content.
739
- // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
740
- // left margin (for left drawer) or right margin (for right the drawer).
741
- // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
742
- // adding to the left or right margin and simultaneously subtracting the same amount of
743
- // margin from the other side.
744
-
745
- let left = 0 ;
746
- let right = 0 ;
747
-
748
- if ( this . _left && this . _left . opened ) {
749
- if ( this . _left . mode == 'side' ) {
750
- left += this . _left . _width ;
751
- } else if ( this . _left . mode == 'push' ) {
752
- let width = this . _left . _width ;
753
- left += width ;
754
- right -= width ;
755
- }
756
- }
757
-
758
- if ( this . _right && this . _right . opened ) {
759
- if ( this . _right . mode == 'side' ) {
760
- right += this . _right . _width ;
761
- } else if ( this . _right . mode == 'push' ) {
762
- let width = this . _right . _width ;
763
- right += width ;
764
- left -= width ;
765
- }
766
- }
767
-
768
- // If either `right` or `left` is zero, don't set a style to the element. This
769
- // allows users to specify a custom size via CSS class in SSR scenarios where the
770
- // measured widths will always be zero. Note that we reset to `null` here, rather
771
- // than below, in order to ensure that the types in the `if` below are consistent.
772
- left = left || null ! ;
773
- right = right || null ! ;
774
-
775
- if ( left !== this . _contentMargins . left || right !== this . _contentMargins . right ) {
776
- this . _contentMargins = { left, right} ;
777
-
778
- // Pull back into the NgZone since in some cases we could be outside. We need to be careful
779
- // to do it only when something changed, otherwise we can end up hitting the zone too often.
780
- this . _ngZone . run ( ( ) => this . _contentMarginChanges . next ( this . _contentMargins ) ) ;
781
- }
782
-
783
- }
784
783
}
0 commit comments