1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

fix: Editor[autoFocus] should work, close: #1669 (#1733)

This commit is contained in:
Benjy Cui
2018-03-28 14:15:51 +08:00
committed by Ian Storm Taylor
parent 4346ad0e3f
commit a325696339
4 changed files with 7 additions and 9 deletions

View File

@@ -40,7 +40,6 @@ class Content extends React.Component {
static propTypes = {
autoCorrect: Types.bool.isRequired,
autoFocus: Types.bool.isRequired,
children: Types.any.isRequired,
className: Types.string,
editor: Types.object.isRequired,
@@ -87,11 +86,9 @@ class Content extends React.Component {
*
* - Add native DOM event listeners.
* - Update the selection, in case it starts focused.
* - Focus the editor if `autoFocus` is set.
*/
componentDidMount = () => {
const { editor } = this.props
const window = getWindow(this.element)
window.document.addEventListener(
@@ -105,10 +102,6 @@ class Content extends React.Component {
}
this.updateSelection()
if (this.props.autoFocus) {
editor.focus()
}
}
/**

View File

@@ -145,11 +145,16 @@ class Editor extends React.Component {
}
/**
* When the component first mounts, flush any temporary changes.
* When the component first mounts, flush any temporary changes,
* and then, focus the editor if `autoFocus` is set.
*/
componentDidMount = () => {
this.flushChange()
if (this.props.autoFocus) {
this.focus()
}
}
/**

View File

@@ -602,7 +602,6 @@ function AfterPlugin() {
<Content
{...handlers}
autoCorrect={props.autoCorrect}
autoFocus={props.autoFocus}
className={props.className}
children={props.children}
editor={editor}