I'm having a really hard time to remove the yellow background on autofill from the Material UI TextField component.
In older versions I did it this way:
const inputStyle = { WebkitBoxShadow: '0 0 0 1000px white inset' };
<TextField
...
inputStyle={inputStyle}
/>
But in the recent version the inputStyle
prop was removed and added InputProps
instead.
I've tried to remove it this way, but the yellow background color still appears:
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
const styles = {
root: {
':-webkit-autofill': {
WebkitBoxShadow: '0 0 0 1000px white inset',
backgroundColor: 'red !important'
}
},
input: {
':-webkit-autofill': {
WebkitBoxShadow: '0 0 0 1000px white inset',
backgroundColor: 'red !important'
}
}
};
const renderTextField = (props) => {
const {
classes,
label,
input,
meta: { touched, error },
...custom
} = props;
return (
<TextField
label={label}
placeholder={label}
error={touched && error}
helperText={touched && error}
className={classes.root}
InputProps={{
className: classes.input
}}
{...input}
{...custom}
/>
);
}
renderTextField.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(renderTextField);