material icon indicating copy to clipboard operation
material copied to clipboard

md-input-container: Password label not floating with Chrome password-manager auto-fill

Open SebiH opened this issue 11 years ago • 66 comments

When using the password manager in Chrome to automatically fill in username & password on two md-input-containers, the password label will not float until some action (e.g. clicking anywhere on the page) is done:

After initial page load: image

After clicking anywhere: image

Reproducing this isn't very easy, since services like Plnkr or CodePen either won't trigger the password manager or the auto-fill; however this GitHub page / repository should provide an environment where it should be reproducible: Site: http://sebih.github.io/angular-material-pwmanagerbug/ Repo: https://github.com/SebiH/angular-material-pwmanagerbug

As there isn't any password authentification, simply type in something to (hopefully) trigger Chrome's password manager, save password and use the link to go back to the login page.

One interesting thing to note is that refreshing the login page does not seem to recreate the faulty state; however navigation via links breaks the password field again.

It seems to work properly in FireFox 35. I'm using Chrome 40, but noticed it in previous versions, too.

SebiH avatar Feb 02 '15 16:02 SebiH

Pretty sure this is due to a bug in Chrome where password autofill doesn't trigger a change on inputs. Not sure there's much we can do about it until it gets resolved.

marcysutton avatar Apr 14 '15 21:04 marcysutton

I know this is closed, but this has been a Chrome bug for some time and it may not be resolved for a while for all I know. So, I think, in the spirit of finding some solution as a workaround, this might be useful to people:

document.querySelector("input[type=password]").value = " ";
document.querySelector("input[type=password]").value = "";
document.querySelector("input[type=password]").blur()

This clears an autocomplete value, so there is some drawback to this approach. However, it looks nicer. You might also be able to use autocomplete="off", but I haven't been able to solve this issue that way.

morrissinger avatar Jul 07 '15 01:07 morrissinger

Should be fixed in #master with SHA a64291b3542be31abe5e79b098fef9b35aed375a

ThomasBurleson avatar Jul 07 '15 01:07 ThomasBurleson

Problem seems to persist on Chrome (v43). I've updated the test repo/site since it returned 404, but should be up now again. Will test the workaround later.

SebiH avatar Jul 07 '15 10:07 SebiH

I don't think we are out of the woods just yet, even given a64291b. I tried a few things to determine this. I:

  • Bower installed angular-material: bower install --save angular-material. This did not fix the problem.
  • Bower installed angular-material#master: bower install --save angular-material#master. This did not fix the problem.
  • Bower installed a64291b: bower install --save angular-material#a64291b. This did not fix the problem.
  • Built angular-material from a64291b: git clone https://github.com/angular/material.git; cd material; npm install; gulp build and then I copied the build over to the project where I am using angular-material and rebuilt my project. This did not fix the problem.

morrissinger avatar Jul 07 '15 14:07 morrissinger

@Splaktar - can you investigate this?

ThomasBurleson avatar Jul 07 '15 14:07 ThomasBurleson

Another point: the bug appears to have an intermittent nature. I can refresh @SebiH's repo/site and sometimes see the issue and sometimes not see the issue.

Here is my screenshot:

intermittent

morrissinger avatar Jul 07 '15 14:07 morrissinger

@morrissinger Seems to be related to keyboard events, possibly? On my machine, when refreshing via navigation or clicking the reload button with the mouse, the password label will not position itself correctly. When refreshing with F5, it works as expected.

SebiH avatar Jul 07 '15 15:07 SebiH

This is because of this weird Chrome behavior: The value of autofilled password field is not set until user do any kind of interaction with page, including clicking somewhere or touching almost anything in keyboard! This is described in more detail here. I don't know it's because of security or something but it becomes bolder in angular-material, because of the floating label, however it exists even in big websites like Dropbox I tried a various kinds of workarounds including simulating mouse or keyboard interaction, but none of them worked! It seems to be such an intractable bug! One possible amelioration is to use "md-no-float", but doing that, not only you will lose the awesomeness of floating label, but also if you want to use form invalidity state to enable or disable submit button, problem remains!

alirezamirian avatar Jul 20 '15 15:07 alirezamirian

As @SebiH stated in his last comment, this does have some interaction with exactly how the page is refreshed.

  • Doing a ctrl-R or F5 keyboard refresh causes the input to render correctly. This is likely due to the key release triggering Chrome's input detection.
  • Doing a soft refresh via the browser button causes the input to render incorrectly.
  • Doing a hard refresh via the browser button while holding shift causes the input to render correctly, in some cases. This is because the shift key is released, that event triggers Chrome to detect interaction and then process the auto filled input (i.e. float the text).

Just pressing any key after reloading the page w/ a problem causes the input to float the text properly.

Based on the two Chrome bugs referenced in this issue plus an additional duplicate Chrome bug (https://code.google.com/p/chromium/issues/detail?id=398805), this appears to be Working as Intended in Chrome.

There are hacks available. TBosch came up with https://github.com/tbosch/autofill-event just for this kind of issue. Unfortunately, I was not able to get that to work for me with the latest Angular about 9 months ago.

I was able to solve this in one project for Firefox by using a $timeout, details here: http://stackoverflow.com/a/23919364/633107

But this hack does not appear to work for Chrome due to the above mentioned bugs related to Chrome AutoFill. The ngModel is never updated with the value from AutoFill until the user interacts with the page in some way.

Also as for the reason that the Placeholder text does not behave properly, this is related to the fact that md-input uses a <label> instead of a placeholder. Chrome doesn't handle labels like a placeholders as per the spec.

Splaktar avatar Jul 22 '15 03:07 Splaktar

Same issue with using md-label's placeholder attribute: http://splaktar.github.io/angular-material-pwmanagerbug/

It doesn't actually use the browser's placeholder feature. It just adds it as a label with float feature enabled via onClick handler.

@alirezamirian suggested using md-no-float for type="password" inputs. This might be the best option available at this time.

Splaktar avatar Jul 22 '15 04:07 Splaktar

md-no-float doesn't appear to fix the label issue with password fields. Using Angular Materials v0.10.0

sjlynch avatar Jul 28 '15 22:07 sjlynch

After click on any Element, also the body - the password field regonized a change, and the input moved to top. I have tried to trigger the click event, unfortunately without success.

$timeout(function(){
        angular.element(document).find('body').triggerHandler('click');
        console.log('click but no changes');
      }, 150);

Does anyone have any idea why this is a failure?

webdesignberlin avatar Jul 30 '15 09:07 webdesignberlin

@webdesignberlin Yes, Chrome browser is purposely keeping the value from being given to the element until the user interacts with the page. This is done for security reasons. They only make it look like the value has been entered, but they don't actually pass the value to the element until interaction happens. They have patched up all of the hacks to get around this (like your example) that I have been able to find. I tried at least 10 different approaches without any luck.

Splaktar avatar Jul 31 '15 01:07 Splaktar

@Splaktar That's not so great. Thanks for the information. Safety first. The only pity is that we live in a world where we have to pay attention to such things.

webdesignberlin avatar Jul 31 '15 06:07 webdesignberlin

@sjlynch you should use it as class on label.

alirezamirian avatar Aug 03 '15 18:08 alirezamirian

God I wish there was a way to disable that stupid autofill completely. Along with it's annoying yellow background.

fxck avatar Aug 12 '15 08:08 fxck

Status: need more discussion about how to address this

jelbourn avatar Aug 14 '15 16:08 jelbourn

@alirezamirian Thanks, that fixed it and it's a pretty acceptable solution.

sjlynch avatar Aug 17 '15 14:08 sjlynch

Setting focus to the password field seems to work as well (with some 1s delay):

angular.element('#password').focus();

Edit: actually it seems to help sometimes, sometimes with delay, sometimes not at all. Might work with tuning $timeouts or something but meh...

simison avatar Aug 27 '15 11:08 simison