_index.scss 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // We want overlays to always appear over user content, so set a baseline
  2. // very high z-index for the overlay container, which is where we create the new
  3. // stacking context for all overlays.
  4. $overlay-container-z-index: 1000 !default;
  5. $overlay-z-index: 1000 !default;
  6. $overlay-backdrop-z-index: 1000 !default;
  7. // Background color for all of the backdrops
  8. $overlay-backdrop-color: rgba(0, 0, 0, 0.32) !default;
  9. // Default backdrop animation is based on the Material Design swift-ease-out.
  10. $backdrop-animation-duration: 400ms !default;
  11. $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
  12. // Conditionally wraps some styles in a layer depending on a flag.
  13. @mixin _conditional-layer($should-wrap) {
  14. @if ($should-wrap) {
  15. @layer cdk-overlay {
  16. @content;
  17. }
  18. } @else {
  19. @content;
  20. }
  21. }
  22. // Structural styles for the overlay. Pass `$wrap-customizable-styles` to emit
  23. // the styles that support customization in a way that makes them easier to change.
  24. @mixin private-overlay-structure($wrap-customizable-styles) {
  25. .cdk-overlay-container, .cdk-global-overlay-wrapper {
  26. // Disable events from being captured on the overlay container.
  27. pointer-events: none;
  28. // The container should be the size of the viewport.
  29. top: 0;
  30. left: 0;
  31. height: 100%;
  32. width: 100%;
  33. }
  34. // The overlay-container is an invisible element which contains all individual overlays.
  35. .cdk-overlay-container {
  36. position: fixed;
  37. @include _conditional-layer($wrap-customizable-styles) {
  38. z-index: $overlay-container-z-index;
  39. }
  40. &:empty {
  41. // Hide the element when it doesn't have any child nodes. This doesn't
  42. // include overlays that have been detached, rather than disposed.
  43. display: none;
  44. }
  45. }
  46. // We use an extra wrapper element in order to use make the overlay itself a flex item.
  47. // This makes centering the overlay easy without running into the subpixel rendering
  48. // problems tied to using `transform` and without interfering with the other position
  49. // strategies.
  50. .cdk-global-overlay-wrapper {
  51. display: flex;
  52. position: absolute;
  53. @include _conditional-layer($wrap-customizable-styles) {
  54. z-index: $overlay-z-index;
  55. }
  56. }
  57. // A single overlay pane.
  58. .cdk-overlay-pane {
  59. // Note: it's important for this one to start off `absolute`,
  60. // in order for us to be able to measure it correctly.
  61. position: absolute;
  62. pointer-events: auto;
  63. box-sizing: border-box;
  64. // For connected-position overlays, we set `display: flex` in
  65. // order to force `max-width` and `max-height` to take effect.
  66. display: flex;
  67. max-width: 100%;
  68. max-height: 100%;
  69. @include _conditional-layer($wrap-customizable-styles) {
  70. z-index: $overlay-z-index;
  71. }
  72. }
  73. .cdk-overlay-backdrop {
  74. position: absolute;
  75. top: 0;
  76. bottom: 0;
  77. left: 0;
  78. right: 0;
  79. pointer-events: auto;
  80. -webkit-tap-highlight-color: transparent;
  81. opacity: 0;
  82. // Removes the tap delay on touch devices (see #30965).
  83. touch-action: manipulation;
  84. @include _conditional-layer($wrap-customizable-styles) {
  85. z-index: $overlay-backdrop-z-index;
  86. transition: opacity $backdrop-animation-duration $backdrop-animation-timing-function;
  87. }
  88. @media (prefers-reduced-motion) {
  89. transition-duration: 1ms;
  90. }
  91. }
  92. .cdk-overlay-backdrop-showing {
  93. opacity: 1;
  94. // Note that we can't import and use the `high-contrast` mixin from `_a11y.scss`, because
  95. // this file will be copied to the top-level `cdk` package when putting together the files
  96. // for npm. Any relative import paths we use here will become invalid once the file is copied.
  97. @media (forced-colors: active) {
  98. // In high contrast mode the rgba background will become solid
  99. // so we need to fall back to making it opaque using `opacity`.
  100. opacity: 0.6;
  101. }
  102. }
  103. .cdk-overlay-dark-backdrop {
  104. @include _conditional-layer($wrap-customizable-styles) {
  105. background: $overlay-backdrop-color;
  106. }
  107. }
  108. .cdk-overlay-transparent-backdrop {
  109. // Define a transition on the visibility so that the `transitionend` event can fire immediately.
  110. transition: visibility 1ms linear, opacity 1ms linear;
  111. visibility: hidden;
  112. opacity: 1;
  113. // Note: as of Firefox 57, having the backdrop be `background: none` will prevent it from
  114. // capturing the user's mouse scroll events. Since we also can't use something like
  115. // `rgba(0, 0, 0, 0)`, we work around the inconsistency by not setting the background at
  116. // all and using `opacity` to make the element transparent.
  117. &.cdk-overlay-backdrop-showing,
  118. .cdk-high-contrast-active & {
  119. opacity: 0;
  120. visibility: visible;
  121. }
  122. }
  123. .cdk-overlay-backdrop-noop-animation {
  124. transition: none;
  125. }
  126. // Overlay parent element used with the connected position strategy. Used to constrain the
  127. // overlay element's size to fit within the viewport.
  128. .cdk-overlay-connected-position-bounding-box {
  129. position: absolute;
  130. // We use `display: flex` on this element exclusively for centering connected overlays.
  131. // When *not* centering, a top/left/bottom/right will be set which overrides the normal
  132. // flex layout.
  133. display: flex;
  134. // We use the `column` direction here to avoid some flexbox issues in Edge
  135. // when using the "grow after open" options.
  136. flex-direction: column;
  137. // Add some dimensions so the element has an `innerText` which some people depend on in tests.
  138. min-width: 1px;
  139. min-height: 1px;
  140. @include _conditional-layer($wrap-customizable-styles) {
  141. z-index: $overlay-z-index;
  142. }
  143. }
  144. // Used when disabling global scrolling.
  145. .cdk-global-scrollblock {
  146. position: fixed;
  147. // Necessary for the content not to lose its width. Note that we're using 100%, instead of
  148. // 100vw, because 100vw includes the width plus the scrollbar, whereas 100% is the width
  149. // that the element had before we made it `fixed`.
  150. width: 100%;
  151. // Note: this will always add a scrollbar to whatever element it is on, which can
  152. // potentially result in double scrollbars. It shouldn't be an issue, because we won't
  153. // block scrolling on a page that doesn't have a scrollbar in the first place.
  154. overflow-y: scroll;
  155. }
  156. }
  157. /// Emits structural styles required for cdk/overlay to function.
  158. @mixin overlay {
  159. @include private-overlay-structure(false);
  160. }