MCPcopy
hub / github.com/angular/components / updateContentMargins

Method updateContentMargins

src/material/sidenav/drawer.ts:905–949  ·  view source on GitHub ↗

* Recalculates and updates the inline styles for the content. Note that this should be used * sparingly, because it causes a reflow.

()

Source from the content-addressed store, hash-verified

903 * sparingly, because it causes a reflow.
904 */
905 updateContentMargins() {
906 // 1. For drawers in `over` mode, they don't affect the content.
907 // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
908 // left margin (for left drawer) or right margin (for right the drawer).
909 // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
910 // adding to the left or right margin and simultaneously subtracting the same amount of
911 // margin from the other side.
912 let left = 0;
913 let right = 0;
914
915 if (this._left && this._left.opened) {
916 if (this._left.mode == 'side') {
917 left += this._left._getWidth();
918 } else if (this._left.mode == 'push') {
919 const width = this._left._getWidth();
920 left += width;
921 right -= width;
922 }
923 }
924
925 if (this._right && this._right.opened) {
926 if (this._right.mode == 'side') {
927 right += this._right._getWidth();
928 } else if (this._right.mode == 'push') {
929 const width = this._right._getWidth();
930 right += width;
931 left -= width;
932 }
933 }
934
935 // If either `right` or `left` is zero, don't set a style to the element. This
936 // allows users to specify a custom size via CSS class in SSR scenarios where the
937 // measured widths will always be zero. Note that we reset to `null` here, rather
938 // than below, in order to ensure that the types in the `if` below are consistent.
939 left = left || null!;
940 right = right || null!;
941
942 if (left !== this._contentMargins.left || right !== this._contentMargins.right) {
943 this._contentMargins = {left, right};
944
945 // Pull back into the NgZone since in some cases we could be outside. We need to be careful
946 // to do it only when something changed, otherwise we can end up hitting the zone too often.
947 this._ngZone.run(() => this._contentMarginChanges.next(this._contentMargins));
948 }
949 }
950
951 ngDoCheck() {
952 // If users opted into autosizing, do a check every change detection cycle.

Callers 4

constructorMethod · 0.95
ngAfterContentInitMethod · 0.95
_watchDrawerToggleMethod · 0.95
_watchDrawerModeMethod · 0.95

Calls 2

_getWidthMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected