如何确保我的界面上的唯一draft-js
文本框在页面加载时自动对焦?
有一个名为focus
的文档化方法,但我不确定实现所需的语法。
答案 0 :(得分:2)
请参阅here
基本上,你做的事情就像
<Editor ref="someRef" />
和
componentDidMount = () => {
this.refs.someRef.focus();
}
答案 1 :(得分:1)
如果您的编辑器是使用某个默认值启动的,那么仅执行this.refs.editor.focus()
就会在文本开头出现光标。因此,要将光标移到末尾,我们需要在componentDidMount
componentDidMount() {
this.setState({
editorState: EditorState.moveFocusToEnd(this.state.editorState), // EditorState imported from draft-js
});
}