【发布时间】:2019-07-09 10:54:55
【问题描述】:
我很难从 Material UI TextField 组件中移除自动填充的黄色背景。
在旧版本中我是这样做的:
const inputStyle = { WebkitBoxShadow: '0 0 0 1000px white inset' };
<TextField
...
inputStyle={inputStyle}
/>
但在最近的版本中,inputStyle 属性被删除并添加了InputProps。
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);
【问题讨论】:
-
你能分享一个代码沙箱的链接吗?或者提到如何复制它
标签: reactjs material-ui jss