-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Handle Chrome autofill #14427
Comments
This need to fix this problem! #14453 might provide some ways to address the problem. |
Sorry for the delayed response. I will try and create a small reproduction when time permits later this week. In the mean time I have a temporary fix in place - setting autoFocus on any one of the Textfields solves the issue. ` <TextField
required
**autoFocus**
variant="outlined"
id="username"
label="mobile number"
defaultValue=""
margin="normal"
name="username"
type="tel"
onChange={this.handleChange}
error={!this.state.validMobile}
autoComplete="tel-national username"
/> |
Doesn't seem to work for me. |
@garygrubb I did this via a theme override:
Not ideal, but it's something. The alternative is to use a box-shadow to fill the input: https://stackoverflow.com/questions/2781549/removing-input-background-colour-for-chrome-autocomplete |
@oliviertassinari This might do the trick: https://stackoverflow.com/a/41530164/396889 |
Also, FYI: facebook/react#1159 |
@MarkMurphy Any idea how I could reproduce the problem? |
For me, I created a simple username and password form and allowed Chrome to remember my credentials. Using Chrome 72.0.3626.119 on MacOS High Sierra 10.13.6 @material-ui/core version "3.8.1" |
@MarkMurphy I could reproduce it with https://material-ui.com/getting-started/page-layout-examples/sign-in/: This is with the text field standard variant. So, we can notice two issues:
Let's try with the outlined variant now. We can use this page: https://deploy-preview-14499--material-ui.netlify.com/getting-started/page-layout-examples/sign-in-side/ |
It seems like its a chrome autofill problem. If we were provided with ways to detect chrome's autofill it'd be an easy fix... but Im not aware of any solution. Only solution was to turn off autocomplete/autofill for all textfields. |
Workaround documentation:
|
Thanks @cezarderevlean , I got rid of the yellow background, Now just need to figure out how to remove the greyed out helper text. |
If you don't want to "disable" autofill as described in the first link I've put above, keep in mind that after autofill, it will appear like in your screenshot only when page refreshed by a code change in Also, if what I've said above proves untrue, one workaround you can implement is always keep the placeholder shrinked with this prop on
|
@cezarderevlean thanks. You are right. A normal browser refresh works fine. |
I don't know how I missed it but @MarkMurphy had a similar solution way back & it uses material theme override which is a bit cleaner for use case. Thanks Mark. |
Thanks, this worked for me. |
Setting |
Update: I guess I jumped the gun here. My solution below seems to only work for plain react -- not MUI. Any ideas why? For folks wanting to get the actual values of the input, instead of just detecting the presence of the values (see #14427 (comment)), I've come up with a solution detailed in this SO article: https://stackoverflow.com/questions/35049555/chrome-autofill-autocomplete-no-value-for-password/56157489#56157489. The link has a good history of this overall issue that affects Chrome in general.
Basically, I force a mouse click on the input so Chrome sets the value on the input. Then at a later point when the value is ready, I grab the value. It's definitely hacky, but Chrome leaves us with no options... (see details of Chrome's stance in the SO article). |
TL;DR: This is a browser issue. They do not consistently fire input events when autofilling forms. This is an issue at the browser level. If I click inside the page and then reload it correctly dispatches input events. If I click on the page, click in the navbar it only stops working on the second enter. If I land on the page by copying the link to the page and entering it in the navbar it also works. I'm not even sure we can fix this for all browsers since when polled the input value is still empty even if autofilled. There's a neat trick for chrome only. Will investigate if only chrome has these issues. |
@eps1lon Have you opened a bug in Chromium if this is Chromium related? |
Thank you this helped solve the issue for me! |
Thanks to @killmenot and @pyzenberg
|
I still see it in v5 why is this issue closed? |
Not the best solution but it's the only one that working right now:
Change #111111 to your background color. I don't like this solution but it's the only one that working right now (V5). |
HI there, |
My hero. |
I'm to! |
Opened a bug at Chromium because it is related to Chromium or its Blink Engine. https://bugs.chromium.org/p/chromium/issues/detail?id=1405170 |
Any updates? |
This issue is still relevant. |
Try using the |
I have a simple solution for that, return Here's the 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"
/> |
Great timing! Had to fix a bug regarding this today and setting initial values to |
Do not use React or JS to solve this. This issue can be easily solved by using CSS selectors. Try using the -internal-autofill-previewed selector on css, e.g. input:-internal-autofill-previewed to e.g; hide your placeholder text. Read more at https://bugs.chromium.org/p/chromium/issues/detail?id=1405170 |
Thanks a lot! This worked for me 👍 |
The problem is present in last verison, any fix? |
I found another workaround if you want to keep the autofill styles but hide the placeholder until the user focuses the input. It's not very clean but it works at least:
|
Avoid JS or React.js solutions, simply use these CSS selectors internal-autofill-previewed selector, as described at https://bugs.chromium.org/p/chromium/issues/detail?id=1405170 |
What if we make it in another way making controlled labels by InputLabelProps(shrink):
@oliviertassinari Wdyt? |
This can be partially fixed if you are using Example: const form = useForm<AuthUserDto>({
resolver: yupResolver(schema),
defaultValues: {
email: undefined,
password: undefined,
},
reValidateMode: 'onChange',
mode: 'onChange',
}); |
This is how I fixed the overlap of autofill and label. I added this to theme. NOTE: I used a specific selectors for outlined textfields, for the other variants, selectors may vary. This puts all of your textfield labels which are autofilled into notched position initially. If you wish to remove the background color also, there are working solutions above. MuiTextField: {
styleOverrides: {
root: {
// Puts the label into notched position
'.MuiInputLabel-outlined:has(+ .MuiOutlinedInput-root > .MuiOutlinedInput-input:-webkit-autofill)': {
transform: 'translate(14px, -9px) scale(0.75)',
},
// Creates a hole around the text inside the border
'.MuiOutlinedInput-input:-webkit-autofill + .MuiOutlinedInput-notchedOutline > legend': {
maxWidth: '100%',
},
},
},
},
``` |
Any updates on this issue? |
There is a display issue in the TextField outlined variant when chrome pre-fills the text box on initial page load. The auto filled text overwrites the label. See below screenshot.
Also notice the yellow background for auto filled text, can it be overridden?
MUI version 3.9.2
The text was updated successfully, but these errors were encountered: