2016-12-01 57 views
2

我目前实现Redux-Form以便将InputFields添加到我的应用程序。是否有办法手动关注子组件的输入?React专注于子组件输入

代码添加子组件:

<Field name="Quantity" ref="quantity" onKeyPress={(event) => this.handleKeyPress('inventory', event)} component={ InputField }/> 

代码子组件:

render() { 
    const { input } = this.props; 
    const inputClass = classNames({ 'parsley-error': this.props.meta.touched && this.props.meta.error }, 'form-control') 
return (
    <div> 
     {this.props.meta.touched && this.props.meta.error && <span className="parsley-error-message">{this.props.meta.error}</span>} 
     <Input {...input} className={inputClass} onKeyPress={this.props.onKeyPress} standalone type="text" placeholder={this.props.placeholder}/> 
    </div> 
    ) 
} 

当前实现企图焦点:

handleKeyPress(value, event){ 
    if(event.charCode == 13){ 
    this.refs["inventory"].getDOMNode().focus(); 
    } 
} 

我硬编码为重点库存只为测试目的

回答

1

内,您的输入组件,你应该能够做到:

`<input type="text" autoFocus />` 

注意F的资本化。我没有对新生成的组件进行测试,但理论上它应该起作用。