我目前正在尝试将自定义数据属性设置为TextField组件:
class TestTextField extends React.Component {
componentDidMount() {console.log(this._input)}
render() {
return (
<TextField
label="Label 1"
InputProps={{placeholder: 'Input 1', 'data-state': 'Data State 1'}}
margin="normal"
inputRef={(elem) => {this._input = elem}}
/>
)
}
}
但是,我无法让data-state
显示控制台日志
<textarea rows="1" class="MuiTextarea-textarea-67 MuiInput-input-56 MuiInput-inputMultiline-64" placeholder="Input 1" type="text">
TextField不支持自定义属性吗?我使用的是v1.0.0-beta.6(https://material-ui-1dab0.firebaseapp.com/api/text-field/)
答案 0 :(得分:5)
正如您所看到的,自定义道具是passed to the FormControl component。您想要的is probably inputProps
passed down to the actual <input />
("input"
默认为{{1}})
答案 1 :(得分:2)
如果其他人没有注意到,@ pier-paolo-ramon则说使用inputProps
道具代替InputProps
道具。密切注意大小写。
<TextField
inputProps={{placeholder: 'Input 1', 'data-state': 'Data State 1'}}
/>