2

So, I have a Material UI TextField control and currently is changing it's background color after selecting a text from the sugestions.

<TextField 
  id="username"
  name="username"
  size="small"
  variant="outlined"
  className={classes.inputFields}
  value={ username || "" }
  onChange={event => setUsername(event.target.value)}
  InputProps={{
    className: classes.multilineColor
  }}
  fullWidth/>

How can I keep my current bg color?

IBot
  • 356
  • 3
  • 20

1 Answers1

1

I recently came across the same issue and could fix it with the following code:

...

const useStyles = makeStyles((theme) => ({
  input: {
    "&:-webkit-autofill": {
      WebkitBoxShadow: "0 0 0 0 100px " + theme.palette.primary.main + " inset",
      backgroundColor: "#fafafa !important;",
      backgroundClip: "content-box !important",
    },
  },
}));

...

const yourComponent = () => {
  const classes = useStyles();
  
  ...

  return (
     <TextField 
         id="username"
         name="username"
         size="small"
         variant="outlined"
         className={classes.inputFields}
         value={ username || "" }
         onChange={event => setUsername(event.target.value)}
         inputProps={{ className: classes.input }}
         fullWidth
     />
     ...
  );

}
yun_jay
  • 1,050
  • 6
  • 20