Currently, I have a styled TextField. When I start to type in the email field, autofill choices appear. If I select one of the autofill choices, the background of the TextField turns white with black text. I want to change these styles.
I've tried this:
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import React from "react";
const styles = {
underline: {
"&::before": {
borderBottom: "1px solid #90caf9"
},
"&:hover:not(.Mui-disabled):before": {
borderBottom: "2px solid #90caf9"
},
"&::after": {
borderBottom: "2px solid #90caf9"
}
},
input: {
"&:-webkit-autofill": {
WebkitBoxShadow: "0 0 0 1000px black inset"
}
}
};
const DarkTextField = withStyles(styles)(props => {
const { classes, ...other } = props;
return <TextField InputProps={{ className: classes.underline }} {...other} />;
});
export default DarkTextField;
Changed DarkTextField component to the following in light of comments:
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import classNames from "classnames";
import React from "react";
const styles = {
underline: {
"&::before": {
borderBottom: "1px solid #90caf9"
},
"&:hover:not(.Mui-disabled):before": {
borderBottom: "2px solid #90caf9"
},
"&::after": {
borderBottom: "2px solid #90caf9"
}
},
input: {
"&:-webkit-autofill": {
WebkitBoxShadow: "0 0 0 1000px black inset"
}
}
};
const DarkTextField = withStyles(styles)(props => {
const { classes, ...other } = props;
return <TextField InputProps={ classNames("classes.underline", "classes.input") } {...other} />;
});
export default DarkTextField;
The above made no change.
- Are either of the above approaches correct (other than the missing className in InputProps)?
- How do I use more than one className in the InputProps?