Skip to content

Commit d2cdca8

Browse files
committed
use filter/backface-visibility to address label jumpiness
1 parent ce0cec3 commit d2cdca8

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
$mat-form-field-legacy-dedupe: 0;
3131

3232
// Applies a floating label above the form field control itself.
33-
@mixin _mat-form-field-label-floating($font-scale, $infix-padding, $infix-margin-top) {
33+
@mixin _mat-form-field-legacy-label-floating($font-scale, $infix-padding, $infix-margin-top) {
3434
// We use perspective to fix the text blurriness as described here:
3535
// http://www.useragentman.com/blog/2014/05/04/fixing-typography-inside-of-2-d-css-transforms/
3636
// This results in a small jitter after the label floats on Firefox, which the
@@ -83,21 +83,21 @@ $mat-form-field-legacy-dedupe: 0;
8383
&.mat-form-field-can-float {
8484
&.mat-form-field-should-float .mat-form-field-label,
8585
.mat-input-server:focus + .mat-form-field-label-wrapper .mat-form-field-label {
86-
@include _mat-form-field-label-floating(
86+
@include _mat-form-field-legacy-label-floating(
8787
$subscript-font-scale, $infix-padding, $infix-margin-top);
8888
}
8989

9090
.mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-label-wrapper
9191
.mat-form-field-label {
92-
@include _mat-form-field-label-floating(
92+
@include _mat-form-field-legacy-label-floating(
9393
$subscript-font-scale, $infix-padding, $infix-margin-top);
9494
}
9595

9696
// Server-side rendered matInput with a label attribute but label not shown
9797
// (used as a pure CSS stand-in for mat-form-field-should-float).
9898
.mat-input-server[label]:not(:label-shown) + .mat-form-field-label-wrapper
9999
.mat-form-field-label {
100-
@include _mat-form-field-label-floating(
100+
@include _mat-form-field-legacy-label-floating(
101101
$subscript-font-scale, $infix-padding, $infix-margin-top);
102102
}
103103
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,13 @@ $mat-form-field-dedupe: 0;
105105

106106
// Applies a floating label above the form field control itself.
107107
@mixin _mat-form-field-label-floating($font-scale, $infix-padding, $infix-margin-top) {
108-
// We use perspective to fix the text blurriness as described here:
109-
// http://www.useragentman.com/blog/2014/05/04/fixing-typography-inside-of-2-d-css-transforms/
110-
// This results in a small jitter after the label floats on Firefox, which the
111-
// translateZ fixes.
112-
transform: translateY(-$infix-margin-top - $infix-padding) scale($font-scale) perspective(100px)
113-
translateZ(0.001px + $mat-form-field-dedupe);
114-
// The tricks above used to smooth out the animation on chrome and firefox actually make things
115-
// worse on IE, so we don't include them in the IE version.
116-
-ms-transform: translateY(-$infix-margin-top - $infix-padding + $mat-form-field-dedupe)
117-
scale($font-scale);
118-
108+
transform: translateY(-$infix-margin-top - $infix-padding + $mat-form-field-dedupe)
109+
scale($font-scale);
119110
width: 100% / $font-scale + $mat-form-field-dedupe;
120111

112+
// Prevent text bluriness when label is floating.
113+
backface-visibility: initial;
114+
121115
$mat-form-field-dedupe: $mat-form-field-dedupe + 0.00001 !global;
122116
}
123117

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@import '../core/style/vendor-prefixes';
33

44

5-
// Styles that only apply to the standard variant of the form-field.
5+
// Styles that only apply to the box variant of the form-field.
66

77
// The border radius for the form field box.
88
$mat-form-field-box-border-radius: 4px !default;
@@ -28,9 +28,7 @@ $mat-form-field-box-subscript-padding:
2828
}
2929

3030
.mat-form-field-label {
31-
// The perspective helps smooth out animations on Chrome and Firefox but isn't needed on IE.
32-
transform: translateY(-50%) perspective(100px);
33-
-ms-transform: translateY(-50%);
31+
transform: translateY(-50%);
3432
}
3533

3634
.mat-form-field-underline {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ $mat-form-field-legacy-underline-height: 1px !default;
99

1010

1111
.mat-form-field-variant-legacy {
12+
.mat-form-field-label-wrapper {
13+
filter: initial;
14+
}
15+
16+
.mat-form-field-label {
17+
backface-visibility: initial;
18+
19+
transform: perspective(100px);
20+
-ms-transform: none;
21+
}
22+
1223
// The underline is what's shown under the control, its prefix and its suffix.
1324
// The ripple is the blue animation coming on top of it.
1425
.mat-form-field-underline {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ $mat-form-field-default-infix-width: 180px !default;
7878
height: 100%;
7979
overflow: hidden;
8080
pointer-events: none; // We shouldn't catch mouse events (let them through).
81+
82+
// Helps prevent text jumpiness when transforming the label.
83+
filter: blur(0);
8184
}
8285

8386
// The label itself. This is invisible unless it is. The logic to show it is
@@ -97,10 +100,6 @@ $mat-form-field-default-infix-width: 180px !default;
97100
text-overflow: ellipsis;
98101
overflow: hidden;
99102

100-
// The perspective helps smooth out animations on Chrome and Firefox but isn't needed on IE.
101-
transform: perspective(100px);
102-
-ms-transform: none;
103-
104103
transform-origin: 0 0;
105104
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function,
106105
color $swift-ease-out-duration $swift-ease-out-timing-function,
@@ -109,6 +108,9 @@ $mat-form-field-default-infix-width: 180px !default;
109108
// Hide the label initially, and only show it when it's floating or the control is empty.
110109
display: none;
111110

111+
// Helps prevent text jumpiness when transforming the label.
112+
backface-visibility: hidden;
113+
112114
[dir='rtl'] & {
113115
transform-origin: 100% 0;
114116
left: auto;

0 commit comments

Comments
 (0)