|
90 | 90 | } |
91 | 91 | } |
92 | 92 |
|
| 93 | +// Used to make instances of the _mat-form-field-placeholder-floating mixin negligibly different, |
| 94 | +// and prevent Google's CSS Optimizer from collapsing the declarations. This is needed because some |
| 95 | +// of the selectors contain pseudo-classes not recognized in all browsers. If a browser encounters |
| 96 | +// an unknown pseudo-class it will discard the entire rule set. |
| 97 | +$dedupe: 0; |
| 98 | + |
93 | 99 | // Applies a floating placeholder above the form field control itself. |
94 | 100 | @mixin _mat-form-field-placeholder-floating($font-scale, $infix-padding, $infix-margin-top) { |
95 | 101 | // We use perspective to fix the text blurriness as described here: |
96 | 102 | // http://www.useragentman.com/blog/2014/05/04/fixing-typography-inside-of-2-d-css-transforms/ |
97 | 103 | // This results in a small jitter after the label floats on Firefox, which the |
98 | 104 | // translateZ fixes. |
99 | 105 | transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale) perspective(100px) |
100 | | - translateZ(0.001px); |
| 106 | + translateZ(0.001px + $dedupe); |
101 | 107 | // The tricks above used to smooth out the animation on chrome and firefox actually make things |
102 | 108 | // worse on IE, so we don't include them in the IE version. |
103 | | - -ms-transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale); |
| 109 | + -ms-transform: translateY(-$infix-margin-top - $infix-padding + $dedupe) scale($font-scale); |
104 | 110 |
|
105 | | - width: 100% / $font-scale; |
106 | | -} |
| 111 | + width: 100% / $font-scale + $dedupe; |
107 | 112 |
|
108 | | -// This is a total duplicate of the mixin above with insignificant values added to the rules. |
109 | | -// This exists because the mixin is used in two places. When Google's CSS Optimizer runs over this |
110 | | -// css (after compiling from sass), it combines those two declarations into one. However, one of |
111 | | -// those places uses `:-webkit-autofill`. When Firefox encounters this unknown pseuedo-class, |
112 | | -// it ignores the entire rule. To work around this, we force one of the delcarations to be |
113 | | -// technically different but still render the same by adding a tiny value to the transform / width. |
114 | | -@mixin _mat-form-field-placeholder-float-nodedupe($font-scale, $infix-padding, $infix-margin-top) { |
115 | | - transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale) perspective(100px) |
116 | | - translateZ(0.002px); |
117 | | - -ms-transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale); |
118 | | - width: (100% / $font-scale) + 0.0001; |
| 113 | + $dedupe: $dedupe + 0.00001 !global; |
119 | 114 | } |
120 | 115 |
|
121 | 116 | @mixin mat-form-field-typography($config) { |
|
188 | 183 | } |
189 | 184 |
|
190 | 185 | .mat-form-field-can-float { |
191 | | - &.mat-form-field-should-float .mat-form-field-placeholder { |
| 186 | + &.mat-form-field-should-float .mat-form-field-placeholder, |
| 187 | + .mat-input-server:focus + .mat-form-field-placeholder-wrapper .mat-form-field-placeholder { |
192 | 188 | @include _mat-form-field-placeholder-floating( |
193 | | - $subscript-font-scale, $infix-padding, $infix-margin-top); |
| 189 | + $subscript-font-scale, $infix-padding, $infix-margin-top); |
194 | 190 | } |
195 | 191 |
|
196 | 192 | .mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-placeholder-wrapper |
197 | 193 | .mat-form-field-placeholder { |
198 | | - @include _mat-form-field-placeholder-float-nodedupe( |
| 194 | + @include _mat-form-field-placeholder-floating( |
| 195 | + $subscript-font-scale, $infix-padding, $infix-margin-top); |
| 196 | + } |
| 197 | + |
| 198 | + // Server-side rendered matInput with a placeholder attribute but placeholder not shown |
| 199 | + // (used as a pure CSS stand-in for mat-form-field-should-float). |
| 200 | + .mat-input-server[placeholder]:not(:placeholder-shown) + .mat-form-field-placeholder-wrapper |
| 201 | + .mat-form-field-placeholder { |
| 202 | + @include _mat-form-field-placeholder-floating( |
199 | 203 | $subscript-font-scale, $infix-padding, $infix-margin-top); |
200 | 204 | } |
201 | 205 | } |
|
0 commit comments