Skip to content

Commit 602a861

Browse files
devversionjelbourn
authored andcommitted
fix(form-field): placeholder not floating if autofilled (#6839)
If a form-field value is set through autofill, the floating placeholder should float and not overlay the form-field value. This doesn't work in Chrome because the `.mat-form-field-autofill-float` class doesn't exist and can't be set on the form-field control anyway. Fixes #6837
1 parent 3ddf65b commit 602a861

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050
}
5151

52-
.mat-form-field-autofill-float:-webkit-autofill + .mat-form-field-placeholder,
52+
.mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-placeholder,
5353
.mat-focused .mat-form-field-placeholder.mat-form-field-float {
5454
.mat-form-field-required-marker {
5555
color: $required-placeholder-color;
@@ -184,7 +184,7 @@
184184
border-top: $infix-margin-top solid transparent;
185185
}
186186

187-
.mat-form-field-autofill-float {
187+
.mat-form-field-autofill-control {
188188
&:-webkit-autofill + .mat-form-field-placeholder-wrapper .mat-form-field-float {
189189
@include _mat-form-field-placeholder-floating(
190190
$subscript-font-scale, $infix-padding, $infix-margin-top);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $mat-form-field-underline-height: 1px !default;
6565
// This is necessary because these browsers do not actually fire any events when a form auto-fill is
6666
// occurring. Once the autofill is committed, a change event happen and the regular md-form-field
6767
// classes take over to fulfill this behaviour. Assumes the autofill is non-empty.
68-
.mat-form-field-autofill-float:-webkit-autofill + .mat-form-field-placeholder-wrapper {
68+
.mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-placeholder-wrapper {
6969
// The control is still technically empty at this point, so we need to hide non-floating
7070
// placeholders to prevent overlapping with the autofilled value.
7171
.mat-form-field-placeholder {

src/lib/input/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let nextUniqueId = 0;
5252
@Directive({
5353
selector: `input[mdInput], textarea[mdInput], input[matInput], textarea[matInput]`,
5454
host: {
55-
'class': 'mat-input-element',
55+
'class': 'mat-input-element mat-form-field-autofill-control',
5656
// Native input properties that are overwritten by Angular inputs need to be synced with
5757
// the native input element. Otherwise property bindings for those don't work.
5858
'[id]': 'id',

0 commit comments

Comments
 (0)