使用react,我单击第一个输入以显示第二个输入(react-ace 编辑器),如何使第二个输入(react-ace 编辑器)自动获得焦点而第一个输入失去焦点?
constructor(props) {
super(props);
this.state = {
hidden: true,
value: props.value
};
}
...
render() {
return <div className="form-group">
<Input onClick={() => this.showEditor()} onChange={() => false} value={this.props.value}/>
<div className={classNames({'hidden': this.state.hidden})}>
<ReactAceEditor
onLoad={(editor) => {
editor.focus();
}}
/>
</div>
</div>
}
传递focus={true}
给 AceEditor,在input
单击之前不要渲染它。一旦AceEditor
被渲染,它会得到集中,从而造成input
模糊。
已经测试过,它的工作原理。
<input onClick={() => this.setState({ show: true })}/>
{
this.state.show &&
<AceEditor
focus
mode="javascript"
theme="monokai"
onChange={(newValue) => this.code=newValue}
name="UNIQUE_ID_OF_DIV"
editorProps={{$blockScrolling: true}}
/>
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句