Skip to content

Commit b80d23e

Browse files
committed
fix non-floating placeholders
1 parent 866fb52 commit b80d23e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/demo-app/input/input-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<table style="width: 100%" cellspacing="0"><tr>
1010
<td>
11-
<md-input-container style="width: 100%">
11+
<md-input-container style="width: 100%" floatPlaceholder="never">
1212
<input mdInput placeholder="First name">
1313
</md-input-container>
1414
</td>

src/lib/input/input-container.scss

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,17 @@ $mat-input-underline-height: 1px !default;
108108
// Once the autofill is committed, a change event happen and the regular md-input-container
109109
// classes take over to fulfill this behaviour.
110110
// Assumes the autofill is non-empty.
111-
&:-webkit-autofill + .mat-input-placeholder-wrapper .mat-float {
112-
transition: none;
111+
&:-webkit-autofill + .mat-input-placeholder-wrapper {
112+
// The input is still technically empty at this point, so we need to hide non-floating
113+
// placeholders to prevent overlapping with the autofilled value.
114+
.mat-input-placeholder {
115+
display: none;
116+
}
117+
118+
.mat-float {
119+
display: block;
120+
transition: none;
121+
}
113122
}
114123

115124
// Note that we can't use something like visibility: hidden or
@@ -148,7 +157,6 @@ $mat-input-underline-height: 1px !default;
148157

149158
// Put ellipsis text overflow.
150159
width: 100%;
151-
display: block;
152160
white-space: nowrap;
153161
text-overflow: ellipsis;
154162
overflow: hidden;
@@ -162,8 +170,13 @@ $mat-input-underline-height: 1px !default;
162170
color $swift-ease-out-duration $swift-ease-out-timing-function,
163171
width $swift-ease-out-duration $swift-ease-out-timing-function;
164172

165-
&.mat-empty {
166-
cursor: text;
173+
// Hide the placeholder initially, and only show it when it's floating or the input is empty.
174+
display: none;
175+
176+
&.mat-empty,
177+
&.mat-float:not(.mat-empty),
178+
.mat-focused &.mat-float {
179+
display: block;
167180
}
168181

169182
[dir='rtl'] & {

0 commit comments

Comments
 (0)