gpt4 book ai didi

javascript - Draft Js 文本编辑器的自动对焦

转载 作者:行者123 更新时间:2023-11-30 09:36:58 25 4
gpt4 key购买 nike

如何确保我的 UI 上唯一的 draft-js 文本框在页面加载时自动聚焦?

有一个记录的方法叫做 focus ,但是我不确定实现所需的语法。

最佳答案

如果您的编辑器是用一些默认值启动的,那么只需执行 this.refs.editor.focus() 就会使光标位于文本的开头。所以要将光标移动到末尾,我们需要在 componentDidMount

中做这样的事情
  componentDidMount() {
this.setState({
editorState: EditorState.moveFocusToEnd(this.state.editorState), // EditorState imported from draft-js
});
}

https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-plugins-editor/src/Editor/moveSelectionToEnd.js -- 方法链接

关于javascript - Draft Js 文本编辑器的自动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43005952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com