Skip to content

fix(form-field): placeholder not floating if autofilled #6839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/form-field/_form-field-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}
}

.mat-form-field-autofill-float:-webkit-autofill + .mat-form-field-placeholder,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead just add the mat-form-field-autofill-float class to the MdInput? This was intended as a class users could add to custom a MdFormFieldControl to get the same effect, but I forgot to actually add it, haha...

Copy link
Member Author

@devversion devversion Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that involve injecting the parent MdFormField to see if the floating placeholder is enabled or not? (which might not be wrong; just asking)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed discussed feedback from Slack.

.mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-placeholder,
.mat-focused .mat-form-field-placeholder.mat-form-field-float {
.mat-form-field-required-marker {
color: $required-placeholder-color;
Expand Down Expand Up @@ -184,7 +184,7 @@
border-top: $infix-margin-top solid transparent;
}

.mat-form-field-autofill-float {
.mat-form-field-autofill-control {
&:-webkit-autofill + .mat-form-field-placeholder-wrapper .mat-form-field-float {
@include _mat-form-field-placeholder-floating(
$subscript-font-scale, $infix-padding, $infix-margin-top);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/form-field/form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $mat-form-field-underline-height: 1px !default;
// This is necessary because these browsers do not actually fire any events when a form auto-fill is
// occurring. Once the autofill is committed, a change event happen and the regular md-form-field
// classes take over to fulfill this behaviour. Assumes the autofill is non-empty.
.mat-form-field-autofill-float:-webkit-autofill + .mat-form-field-placeholder-wrapper {
.mat-form-field-autofill-control:-webkit-autofill + .mat-form-field-placeholder-wrapper {
// The control is still technically empty at this point, so we need to hide non-floating
// placeholders to prevent overlapping with the autofilled value.
.mat-form-field-placeholder {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let nextUniqueId = 0;
@Directive({
selector: `input[mdInput], textarea[mdInput], input[matInput], textarea[matInput]`,
host: {
'class': 'mat-input-element',
'class': 'mat-input-element mat-form-field-autofill-control',
// Native input properties that are overwritten by Angular inputs need to be synced with
// the native input element. Otherwise property bindings for those don't work.
'[id]': 'id',
Expand Down