Reactjs 反应选择无法设置id

Reactjs 反应选择无法设置id,reactjs,react-redux,Reactjs,React Redux,是否有react select组件且未设置id字段?可以设置一个id吗 <Select id={field} className="reqform-project-dropdown" {...f.props(field)} disabled={ readOnly || onEdit || f.props(field).read_only } clearable={false} optio

是否有react select组件且未设置id字段?可以设置一个id吗

<Select
    id={field}
    className="reqform-project-dropdown"
    {...f.props(field)}
    disabled={
        readOnly ||
        onEdit ||
        f.props(field).read_only
    }
    clearable={false}
    options={this.props.common.tests}
    onChange={this.handleProjChange.bind(this, field,
        f.props(field).multiple,
        'test_req_unique_prefix')}
    labelKey="test_name"
    valueKey="test_req_unique_prefix"
/>


我已经求助于设置父div的id,但似乎很愚蠢,我不能直接为select做这件事。

我没有看到任何关于在其中设置
id
属性的内容,但是您可以使用它来获取对DOM元素的引用,并通过这个对象添加它

class App extends React.Component {
  componentDidMount() {
    this.select.wrapper.id = "myId";
  }

  render() {
    return (
      <div>
        <Select
          ref={ref => { this.select = ref; }}
        />
      </div>
    );
  }
}
类应用程序扩展了React.Component{
componentDidMount(){
this.select.wrapper.id=“myId”;
}
render(){
返回(
{this.select=ref;}}
/>
);
}
}

您可以使用文档中的
输入道具

如果您希望在单击相应标签时获得焦点,则在
inputProps
中传递
id
应该可以

<label htmlFor={'fieldId'} />
<Select inputProps={{ id: 'fieldId' }} /> // should be an object

//应该是一个对象

在react select的版本>=2中,设置id的道具称为
inputId
。像这样使用它:

<Select inputId="your-custom-id" />


您是在谈论库吗?您缺少
道具。您想用这个
id
道具实现什么?想要更可靠的selenium测试id谢谢@Honza Kalfusit的帮助。ThanksIt也适用于CreatableSelect-