-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[TextField] Autofill values not triggering onChange in Chrome #22488
Comments
As mentioned elsewhere, this is related to facebook/react#1159. At the end of that thread, it seems to say that this issue is caused by react ignoring on-change events that come immediately after the input is mounted. Based on that, probably the best solution is to use a If we can agree on a solution, I'd be happy to write up a PR for it. |
A couple of thoughts:
|
Thanks for the reply @oliviertassinari
I'd prefer not to do this b/c my UI function is to disable the submit button until the form values are filled out. As for other libraries, I don't know how they handle that.
Hmm, that's interesting. I hadn't considered that. If I test my codesandbox by focusing the page before the inputs are rendered and they correctly trigger on-change events. Strange tho, that I can trigger an artificial click event on the input field to bypass that functionality... Doesn't really seem like a security feature to me... I'd like to solve this b/c the use-case still stands. When I go to login to my webapp, I can't press the login button until I've clicked elsewhere on the page. Since there is a solution (albeit, not a great one), I think it would be helpful to address. |
Do you get the correct value back or is it empty? |
Do you have a specific reason for doing such? If not, please don't. Let users understand why the form can't go through when they click on the submit button. |
I get the correct value |
It's following the pattern of "only actions when the required information is present". I think that's a pretty common UX pattern and doesn't seem unreasonably weird. |
I had a look at the reproduction, I don't see any significant issue. The change event is fired. If you are not focusing the window, Chrome waits for this action. Also, unless there is a specific opportunity to solve the issue here, better close it. |
Ok, I'll stick with my artificial click hack then. |
I have a simple solution for that, return Here's an example: <TextField
label={errors.email || "Email"}
name={'adminEmail'}
error={!!errors.email}
onChange={handleChange}
value={values.email || null}
variant="outlined"
className={`mb-8 `}
autoComplete="new-password"
/> |
this solution throws a console error but visually it kinda works. |
Does Not work for me! The problem continued... |
Any news about that? |
Unfortunately, no. The problem persists. The Chrome browser can't follow my commands to deactivate the autofill feature. |
Works like a charm |
It works but it gave me the following warning, so I put undefined instead and the problem went away. |
Autofilled values don't trigger onChange event immediately in Chrome
This is a more specific issue originating from #17436 / #14427. Those issues deal with the more broad issue of labels not being positioned correctly. This is just about the onChange values not working correctly.
#14427 partially fixes the onChange issue. With #14427 if you click on the page somewhere, it will trigger onChange, but not immediately after the autofill
Current Behavior 😯
Autofilled inputs don't trigger onChange events in chrome when filled. In @next branch, they trigger onChange, but only after the user clicks somewhere on the page.
Expected Behavior 🤔
Autofilled inputs trigger onChange events in chrome when filled.
Steps to Reproduce 🕹
reproduce: https://react-ts-xphhbf.stackblitz.io/ (you must use the full screen view to reproduce, doesn't happen in the editor iframe)
code: https://stackblitz.com/edit/react-ts-xphhbf?file=index.tsx
Steps:
Context 🔦
I'm trying to setup a login screen where the login button is enabled only when you fill out the necessary inputs.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: