Skip to content

Commit a423987

Browse files
committed
fix box variant text fuzziness
1 parent 30034e3 commit a423987

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

src/lib/form-field/_form-field-box-theme.scss

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,64 @@
3333
}
3434
}
3535

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+
}

src/lib/form-field/_form-field-theme.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ $mat-form-field-dedupe: 0;
124124
// The amount to scale the font for the prefix and suffix icons.
125125
$prefix-suffix-icon-font-scale: 1.5;
126126

127-
// The amount of space between the top of the line and the top of the actual text
128-
// (as a fraction of the font-size).
129-
$line-spacing: ($line-height - 1) / 2;
130127
// The padding on the infix. Mocks show half of the text size.
131128
$infix-padding: 0.5em;
132129
// The margin applied to the form-field-infix to reserve space for the floating label.

src/lib/form-field/form-field-box.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ $mat-form-field-box-subscript-padding:
2727
$mat-form-field-box-side-padding;
2828
}
2929

30-
.mat-form-field-label {
31-
transform: translateY(-50%);
32-
}
33-
3430
.mat-form-field-underline {
3531
height: $mat-form-field-box-border-radius;
3632
border-radius: 0 0 $mat-form-field-box-border-radius $mat-form-field-box-border-radius;

0 commit comments

Comments
 (0)