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

[TextField] Change -webkit-autofill style #283

Closed
zhiqingchen opened this issue Jan 28, 2015 · 18 comments
Closed

[TextField] Change -webkit-autofill style #283

zhiqingchen opened this issue Jan 28, 2015 · 18 comments
Labels
component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@zhiqingchen
Copy link

should we disable -webkit-autofill style

ugly when i use the autofilll value
image
image

@akinnee

This comment has been minimized.

@bjornreppen
Copy link

bjornreppen commented Apr 22, 2015

The information here can be applied to the library: http://stackoverflow.com/questions/2781549/removing-input-background-colour-for-chrome-autocomplete

@akinnee
Copy link

akinnee commented Apr 30, 2015

I think removing it actually reduces user friendliness.

@hai-cea hai-cea changed the title disable -webkit-autofill style in TextField [TextField] disable -webkit-autofill style in TextField Jun 18, 2015
@shaurya947

This comment has been minimized.

@andynoelker

This comment has been minimized.

@olslash

This comment has been minimized.

@mattblackdev

This comment has been minimized.

@mattblackdev
Copy link

mattblackdev commented Mar 18, 2017

I found this bit of a hack, using css transition to delay -webkit-autofill. Only tested in Chrome v56.0.2924.87

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s, color 5000s ease-in-out 0s;
    transition-delay: background-color 5000s, color 5000s;
}

image

@matheusjardimb

This comment has been minimized.

@mbrookes
Copy link
Member

mbrookes commented May 9, 2017

@matheusjardimb This isn't a Material-UI issue.

But, since you asked, LMGTFY:

https://css-tricks.com/snippets/css/change-autocomplete-styles-webkit-browsers/
http://webagility.com/posts/remove-forced-yellow-input-background-in-chrome
https://blog.mariusschulz.com/2016/03/20/how-to-remove-webkits-banana-yellow-autofill-background

@gabrielfaro97
Copy link

gabrielfaro97 commented Apr 2, 2018

you can add this code to your index.css:

input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 30px #FFFFFF inset;
}

@nimahkh

This comment has been minimized.

@edgarfinn
Copy link

edgarfinn commented Jul 16, 2019

@nimahkh Ive just come across the same issue, I wanted to be able to handle this within my Material-ui theme provider (although ideally it would be good for M-UI to maybe have a more elegant way of dealing with this), but the work-around I came to was adding the following to my MUI theme overrides:

overrides: {
  MuiOutlinedInput: {
    input: {
      '&:-webkit-autofill': {
        WebkitBoxShadow: '0 0 0 100px #266798 inset',
        WebkitTextFillColor: '#fff',
      },
    },
  },
}

using this pattern you should be able to apply the style rulings described in this CSS-tricks article.

Hope that helps!

@Emidomenge

This comment has been minimized.

@oliviertassinari oliviertassinari added component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement labels Dec 30, 2019
@mui mui deleted a comment Dec 30, 2019
@mui mui deleted a comment from rmariuzzo Dec 30, 2019
@mui mui deleted a comment from VincentCATILLON Dec 30, 2019
@oliviertassinari oliviertassinari changed the title [TextField] disable -webkit-autofill style in TextField [TextField] Change -webkit-autofill style Dec 30, 2019
@phoxer
Copy link

phoxer commented May 25, 2021

Mi solution was added it on the theme overrides.

overrides: {
   MuiOutlinedInput: {
     input: {
          '&:-webkit-autofill': {
            '-webkit-box-shadow': '0 0 0 100px #000 inset',
            '-webkit-text-fill-color': '#fff'
          }
        }
   }
}

@PabloLION
Copy link
Contributor

In MUI v5, it is

createTheme({
// your other theme props ... 
// one less indent here for readability
components: {
  MuiOutlinedInput: {
    styleOverrides: {
      input: {
        "&:-webkit-autofill": {
          "-webkit-box-shadow": "0 0 0 100px var(--primary-weak) inset",
          "-webkit-text-fill-color": "var(--text-primary)",
        },
      },
    },
  },
},
})

Also, I used this to dynamically change the color. (learned this trick here)

<GlobalStyles
  styles={{
    ":root": {
      "--primary-weak": theme.palette.primary[theme.palette.mode as "dark" | "light"],
      "--text-primary": theme.palette.text.primary    },
  }}
/>

GlobalStyles Tag Doc

@f-a-t-h-e
Copy link

take a look at this code pen

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  transition: background-color 9999s ease-in-out 0s;
}

@julianCast
Copy link

julianCast commented Jun 15, 2023

Another alternative to not apply any color to the autofill:

components: {
    MuiOutlinedInput: {
      styleOverrides: {
        input: {
          "&:-webkit-autofill": {
            backgroundClip: "text",
          },
        },
      },
    },
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests