1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 16:44:22 +02:00

fix editor auto focus (#1438)

current implement of auto focus is buggy, HTMLElement.focus method
have no effect on selection state of editor, another re-render will
cause editor blur unexpectedly.
This commit is contained in:
Raffy Li
2017-12-03 04:06:17 +08:00
committed by Ian Storm Taylor
parent f3b1a806d7
commit b3324db24c

View File

@@ -92,6 +92,8 @@ class Content extends React.Component {
*/ */
componentDidMount = () => { componentDidMount = () => {
const { editor } = this.props
// Restrict scoped of `beforeinput` to mobile. // Restrict scoped of `beforeinput` to mobile.
if ((IS_IOS || IS_ANDROID) && SUPPORTED_EVENTS.beforeinput) { if ((IS_IOS || IS_ANDROID) && SUPPORTED_EVENTS.beforeinput) {
this.element.addEventListener('beforeinput', this.onNativeBeforeInput) this.element.addEventListener('beforeinput', this.onNativeBeforeInput)
@@ -100,7 +102,7 @@ class Content extends React.Component {
this.updateSelection() this.updateSelection()
if (this.props.autoFocus) { if (this.props.autoFocus) {
this.element.focus() editor.focus()
} }
} }