@@ -12,8 +12,20 @@ $overlay-backdrop-color: rgba(0, 0, 0, 0.32) !default;
1212$backdrop-animation-duration : 400ms !default ;
1313$backdrop-animation-timing-function : cubic-bezier (0.25 , 0.8 , 0.25 , 1 ) !default ;
1414
15- /// Emits structural styles required for cdk/overlay to function.
16- @mixin overlay () {
15+ // Conditionally wraps some styles in a layer depending on a flag.
16+ @mixin _conditional-layer ($should-wrap ) {
17+ @if ($should-wrap ) {
18+ @layer cdk-overlay {
19+ @content ;
20+ }
21+ } @else {
22+ @content ;
23+ }
24+ }
25+
26+ // Structural styles for the overlay. Pass `$wrap-customizable-styles` to emit
27+ // the styles that support customization in a way that makes them easier to change.
28+ @mixin private-overlay-structure ($wrap-customizable-styles ) {
1729 .cdk-overlay-container , .cdk-global-overlay-wrapper {
1830 // Disable events from being captured on the overlay container.
1931 pointer-events : none ;
@@ -28,7 +40,10 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
2840 // The overlay-container is an invisible element which contains all individual overlays.
2941 .cdk-overlay-container {
3042 position : fixed ;
31- z-index : $overlay-container-z-index ;
43+
44+ @include _conditional-layer ($wrap-customizable-styles ) {
45+ z-index : $overlay-container-z-index ;
46+ }
3247
3348 & :empty {
3449 // Hide the element when it doesn't have any child nodes. This doesn't
@@ -44,7 +59,10 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
4459 .cdk-global-overlay-wrapper {
4560 display : flex ;
4661 position : absolute ;
47- z-index : $overlay-z-index ;
62+
63+ @include _conditional-layer ($wrap-customizable-styles ) {
64+ z-index : $overlay-z-index ;
65+ }
4866 }
4967
5068 // A single overlay pane.
@@ -54,13 +72,16 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
5472 position : absolute ;
5573 pointer-events : auto ;
5674 box-sizing : border-box ;
57- z-index : $overlay-z-index ;
5875
5976 // For connected-position overlays, we set `display: flex` in
6077 // order to force `max-width` and `max-height` to take effect.
6178 display : flex ;
6279 max-width : 100% ;
6380 max-height : 100% ;
81+
82+ @include _conditional-layer ($wrap-customizable-styles ) {
83+ z-index : $overlay-z-index ;
84+ }
6485 }
6586
6687 .cdk-overlay-backdrop {
@@ -71,11 +92,14 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
7192 left : 0 ;
7293 right : 0 ;
7394
74- z-index : $overlay-backdrop-z-index ;
7595 pointer-events : auto ;
7696 -webkit-tap-highlight-color : transparent ;
77- transition : opacity $backdrop-animation-duration $backdrop-animation-timing-function ;
7897 opacity : 0 ;
98+
99+ @include _conditional-layer ($wrap-customizable-styles ) {
100+ z-index : $overlay-backdrop-z-index ;
101+ transition : opacity $backdrop-animation-duration $backdrop-animation-timing-function ;
102+ }
79103 }
80104
81105 .cdk-overlay-backdrop-showing {
@@ -84,16 +108,17 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
84108 // Note that we can't import and use the `high-contrast` mixin from `_a11y.scss`, because
85109 // this file will be copied to the top-level `cdk` package when putting together the files
86110 // for npm. Any relative import paths we use here will become invalid once the file is copied.
87- .cdk-high-contrast-active & {
111+ @media ( forced-colors : active ) {
88112 // In high contrast mode the rgba background will become solid
89113 // so we need to fall back to making it opaque using `opacity`.
90114 opacity : 0.6 ;
91115 }
92116 }
93117
94118 .cdk-overlay-dark-backdrop {
95- // Add a CSS variable to make this easier to override.
96- background : var (--cdk-overlay-backdrop-dark-color , $overlay-backdrop-color );
119+ @include _conditional-layer ($wrap-customizable-styles ) {
120+ background : $overlay-backdrop-color ;
121+ }
97122 }
98123
99124 .cdk-overlay-transparent-backdrop {
@@ -121,7 +146,6 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
121146 // overlay element's size to fit within the viewport.
122147 .cdk-overlay-connected-position-bounding-box {
123148 position : absolute ;
124- z-index : $overlay-z-index ;
125149
126150 // We use `display: flex` on this element exclusively for centering connected overlays.
127151 // When *not* centering, a top/left/bottom/right will be set which overrides the normal
@@ -135,6 +159,10 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
135159 // Add some dimensions so the element has an `innerText` which some people depend on in tests.
136160 min-width : 1px ;
137161 min-height : 1px ;
162+
163+ @include _conditional-layer ($wrap-customizable-styles ) {
164+ z-index : $overlay-z-index ;
165+ }
138166 }
139167
140168 // Used when disabling global scrolling.
@@ -152,3 +180,8 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
152180 overflow-y : scroll ;
153181 }
154182}
183+
184+ /// Emits structural styles required for cdk/overlay to function.
185+ @mixin overlay {
186+ @include private-overlay-structure (false);
187+ }
0 commit comments