简体   繁体   English

材质UI TextField自定义属性

[英]Material UI TextField Custom Attribute

I am currently trying to set a custom data attribute to a TextField component as such: 我目前正在尝试将自定义数据属性设置为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}}
      />
    )
  }
}

However I can't get data-state to show up with the console log saying 但是我无法通过控制台日志显示data-state

 <textarea rows="1" class="MuiTextarea-textarea-67 MuiInput-input-56 MuiInput-inputMultiline-64" placeholder="Input 1" type="text">

Are custom attributes not supported for TextField? TextField不支持自定义属性吗? I am using v1.0.0-beta.6 ( https://material-ui-1dab0.firebaseapp.com/api/text-field/ ) 我使用的是v1.0.0-beta.6( https://material-ui-1dab0.firebaseapp.com/api/text-field/

As you can see custom props are passed to the FormControl component . 如您所见,自定义道具将传递给FormControl组件 What you want is probably inputProps which is then passed down to the actual <input /> ( InputComponent is "input" by default) 你想要的可能是inputProps然后传递给实际的<input /> (默认情况下InputComponent"input"

In case others didn't notice, @pier-paolo-ramon is saying to use the inputProps prop instead of the InputProps prop. 如果其他人没有注意到,@ pier-paolo-ramon会说使用inputProps prop而不是InputProps prop。 Pay close attention to the case sensitivity. 密切关注区分大小写。

<TextField
  inputProps={{placeholder: 'Input 1', 'data-state': 'Data State 1'}}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM