Skip to content
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

Incorrect initial placeholder position after update to beta.10 #6849

Closed
MaickelHubner opened this issue Sep 5, 2017 · 17 comments
Closed

Incorrect initial placeholder position after update to beta.10 #6849

MaickelHubner opened this issue Sep 5, 2017 · 17 comments
Assignees
Labels
area: material/form-field needs: discussion Further discussion with the team is needed before proceeding P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@MaickelHubner
Copy link

Bug, feature request, or proposal:

When init the component the placeholder is being shown over the content. After the focus it returns to normal

What is the expected behavior?

Placeholder showed in normal position since init

What is the current behavior?

before

after

What are the steps to reproduce?

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular4, Material 2.0.0-beta.10, browser Safari

Is there anything else we should know?

@MaickelHubner
Copy link
Author

I create a plunker, but there it works :-(

http://plnkr.co/edit/X7ZSaGW7t8nFx3KHQ09K?p=preview

@mmalerba
Copy link
Contributor

mmalerba commented Sep 6, 2017

#5692 changed input to use OnPush change detection. It sounds like this may be related to that. Is the data shown in the inputs loaded asynchronously?

@MaickelHubner
Copy link
Author

Does not work too!!!
If I remove the option [formControl]="inputControl" of the input in HTML or if I remove the ? of the [value]="inputValue?.descricao" it worked well (but I receive the TypeError: undefined is not an object (evaluating '_co.inputValue.descricao') error).

@MaickelHubner
Copy link
Author

I also realized that the change in conta.descricao do not appear in ngOnChanges, only in writeValue

@timwright35
Copy link

@mmalerba I am having this issue as well and the data is patched/set after it is received from the server, the form is setup with blank values at first. But even after being added to the form, it is showing up in the inputs, the placeholder does not move till you click into the input.

@willshowell
Copy link
Contributor

@Tempus35 can you reproduce either?

Here's a starter template: http://plnkr.co/edit/jZoIp0f9R4Krrm33w8VR?p=preview

@timwright35
Copy link

timwright35 commented Sep 11, 2017

@willshowell http://plnkr.co/edit/hTVZbkIUChw6SgTWDRFC?p=preview it appears to be when you do what I am doing in the plunker with making a new control or in the case of the component in the code I am working on, a form group.

@mmalerba
Copy link
Contributor

Yep, this is due to OnPush change detection. Using patchValue instead of creating a new FormControl works: http://plnkr.co/edit/TmlV6lRpNRGRFYrpM9S5?p=preview

@crisbeto is there a way for us to detect if they give us a completely new FormControl and run change detection?

@timwright35
Copy link

@mmalerba Another place this is an issue is on login forms, where the input might be filled in via a password manager. When the password manager fills in the inputs the placeholder is not moving up as it once did.

@crisbeto
Copy link
Member

@mmalerba it should be possible to define our own formControl input and react to changes based on it.

@MaickelHubner
Copy link
Author

To fix the problem I simply used the setValue function of the formControl inside the set method:

set inputValue(val) { this._inputValue = val; this.propagateChange(this._inputValue); if (val) { this.inputControl.setValue(val.descricao); } }

@mmalerba
Copy link
Contributor

@crisbeto That works for formControl since it goes on the input, but what if we had a formGroup on some parent element?

@crisbeto
Copy link
Member

Not without defining our own directive that looks for [formGroup] @mmalerba.

@mmalerba
Copy link
Contributor

Ok, so I see a couple ways we could deal with this:

  1. Tell people not to do this
  2. Tell people not to do this, but provide a runChangeDetection method for them to call if they must
  3. Create a directive that matches formControl formGroup formArray any others? Inject that and use it to run change detection appropriately
  4. Go back to ChangeDetectionStrategy.Default

@jelbourn @crisbeto

@jelbourn
Copy link
Member

@kara do you have any input on this?

@mmalerba mmalerba added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Nov 21, 2017
@mmalerba mmalerba added needs: discussion Further discussion with the team is needed before proceeding and removed discussion labels Mar 3, 2020
@zoechi
Copy link

zoechi commented Feb 21, 2021

I'm still seeing this with OnPush and emitEvent: false. Shouldn't emitModelToViewChange:true be enough?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/form-field needs: discussion Further discussion with the team is needed before proceeding P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

8 participants