Skip to content

Commit 26be8c4

Browse files
committed
fix: add transition to placeholder text
1 parent 17ceb9a commit 26be8c4

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/lib/form-field/form-field.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@
88
<div class="mat-input-infix mat-form-field-infix">
99
<ng-content></ng-content>
1010

11-
<span class="mat-form-field-label-wrapper">
11+
<!--
12+
TODO: remove `mat-input-placeholder-wrapper` and `mat-form-field-placeholder-wrapper`
13+
next time we do breaking changes.
14+
-->
15+
<span class="mat-form-field-label-wrapper mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper">
1216
<!-- We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
1317
read if it comes before the control in the DOM. -->
14-
<label class="mat-form-field-label"
18+
19+
<!--
20+
TODO: remove `mat-input-placeholder` and `mat-form-field-placeholder`
21+
next time we do breaking changes.
22+
-->
23+
<label class="mat-form-field-label mat-input-placeholder mat-form-field-placeholder"
1524
[attr.for]="_control.id"
1625
[attr.aria-owns]="_control.id"
1726
[class.mat-empty]="_control.empty && !_shouldAlwaysFloat"

src/lib/input/input.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
display: none;
3838
}
3939

40+
@include input-placeholder {
41+
// Delay the transition until the label has animated about a third of the way through, in
42+
// order to prevent the placeholder from overlapping for a split second.
43+
transition: color $swift-ease-out-duration $swift-ease-out-duration / 3
44+
$swift-ease-out-timing-function;
45+
}
46+
4047
.mat-form-field-hide-placeholder & {
4148
// Note that we can't use something like visibility: hidden or
4249
// display: none, because IE ends up preventing the user from
@@ -45,6 +52,10 @@
4552
// Needs to be !important, because the placeholder will end up inheriting the
4653
// input color in IE, if the consumer overrides it with a higher specificity.
4754
color: transparent !important;
55+
56+
// Remove the transition to prevent the placeholder
57+
// from overlapping when the label comes back down.
58+
transition: none;
4859
}
4960
}
5061
}

src/lib/select/select.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
8989
}
9090

9191
.mat-select-placeholder {
92+
// Delay the transition until the label has animated about a third of the way through, in
93+
// order to prevent the placeholder from overlapping for a split second.
94+
transition: color $swift-ease-out-duration $swift-ease-out-duration / 3
95+
$swift-ease-out-timing-function;
96+
9297
.mat-form-field-hide-placeholder & {
9398
color: transparent;
99+
100+
// Remove the transition to prevent the placeholder
101+
// from overlapping when the label comes back down.
102+
transition: none;
94103
}
95104
}

0 commit comments

Comments
 (0)