1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 13:11:17 +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

@@ -263,6 +263,7 @@ class RichTextExample extends React.Component {
renderNode={this.renderNode} renderNode={this.renderNode}
renderMark={this.renderMark} renderMark={this.renderMark}
spellCheck spellCheck
autoFocus
/> />
</div> </div>
) )

View File

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

View File

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