|
33 | 33 | }
|
34 | 34 | }
|
35 | 35 |
|
36 |
| -@mixin mat-form-field-box-typography($config) {} |
| 36 | +// Used to make instances of the _mat-form-field-label-floating mixin negligibly different, |
| 37 | +// and prevent Google's CSS Optimizer from collapsing the declarations. This is needed because some |
| 38 | +// of the selectors contain pseudo-classes not recognized in all browsers. If a browser encounters |
| 39 | +// an unknown pseudo-class it will discard the entire rule set. |
| 40 | +$mat-form-field-box-dedupe: 0; |
| 41 | + |
| 42 | +// Applies a floating label above the form field control itself. |
| 43 | +@mixin _mat-form-field-box-label-floating($font-scale, $infix-padding, $infix-margin-top) { |
| 44 | + transform: translateY(-$infix-margin-top - $infix-padding + $mat-form-field-box-dedupe) |
| 45 | + scale($font-scale); |
| 46 | + width: 100% / $font-scale + $mat-form-field-box-dedupe; |
| 47 | + |
| 48 | + // Prevent text bluriness when label is floating. |
| 49 | + backface-visibility: initial; |
| 50 | + |
| 51 | + $mat-form-field-box-dedupe: $mat-form-field-box-dedupe + 0.00001 !global; |
| 52 | +} |
| 53 | + |
| 54 | +@mixin mat-form-field-box-typography($config) { |
| 55 | + // The unit-less line-height from the font config. |
| 56 | + $line-height: mat-line-height($config, input); |
| 57 | + // The amount to scale the font for the floating label and subscript. |
| 58 | + $subscript-font-scale: 0.75; |
| 59 | + // The padding on the infix. Mocks show half of the text size. |
| 60 | + $infix-padding: 0.5em; |
| 61 | + // The margin applied to the form-field-infix to reserve space for the floating label. |
| 62 | + $infix-margin-top: 1em * $line-height * $subscript-font-scale; |
| 63 | + // The amount we offset the label in the box variant. |
| 64 | + $box-variant-label-offset: -0.5em * $line-height; |
| 65 | + |
| 66 | + .mat-form-field-variant-box { |
| 67 | + .mat-form-field-label { |
| 68 | + margin-top: $box-variant-label-offset; |
| 69 | + } |
| 70 | + |
| 71 | + &.mat-form-field-can-float { |
| 72 | + &.mat-form-field-should-float .mat-form-field-label, |
| 73 | + .mat-input-server:focus + .mat-form-field-label-wrapper .mat-form-field-label { |
| 74 | + @include _mat-form-field-label-floating( |
| 75 | + $subscript-font-scale, $infix-padding + $box-variant-label-offset, |
| 76 | + $infix-margin-top); |
| 77 | + } |
| 78 | + |
| 79 | + .mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-label-wrapper |
| 80 | + .mat-form-field-label { |
| 81 | + @include _mat-form-field-label-floating( |
| 82 | + $subscript-font-scale, $infix-padding + $box-variant-label-offset, |
| 83 | + $infix-margin-top); |
| 84 | + } |
| 85 | + |
| 86 | + // Server-side rendered matInput with a label attribute but label not shown |
| 87 | + // (used as a pure CSS stand-in for mat-form-field-should-float). |
| 88 | + .mat-input-server[label]:not(:label-shown) + .mat-form-field-label-wrapper |
| 89 | + .mat-form-field-label { |
| 90 | + @include _mat-form-field-label-floating( |
| 91 | + $subscript-font-scale, $infix-padding + $box-variant-label-offset, |
| 92 | + $infix-margin-top); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments