gpt4 book ai didi

reactjs - 如何在 React Material-UI 中覆盖 FormHelperText 样式?

转载 作者:行者123 更新时间:2023-12-04 02:58:07 32 4
gpt4 key购买 nike

我正在使用 React Material-UI库并且不明白如何覆盖 FormHelperText 样式?

const { classes } = this.props
...
<TextField
name='username'
label='Username'
error={this.state.usernameInvalid}
helperText={this.state.usernameError}
classes={{
root: classes.textField,
FormHelperText: classes.helperText // <-- how to override by right way?
}}
onChange={this.handleInputChange}
/>
...
export default withStyles(styles)(SignInPopup)

样式:

const styles = () => ({
textField: {
width: '100%'
},
helperText: {
position: 'absolute',
bottom: '-50%'
}
})

我遇到了这个错误:

Warning: Material-UI: the key `FormHelperText` provided to the classes property is not implemented in FormControl.
You can only override one of the following: root,marginNormal,marginDense,fullWidth

最佳答案

解决方法在这里:

<TextField
name='username'
label='Username'
className={classes.textField}
error={this.state.usernameInvalid}
helperText={this.state.usernameError}
FormHelperTextProps={{ classes: { root: classes.helperText } }} // <- smth like that
onChange={this.handleInputChange}
/>

关于reactjs - 如何在 React Material-UI 中覆盖 FormHelperText 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952889/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com