Skip to content

Commit d6cad2e

Browse files
tonygentilcoreflarnie
authored andcommitted
Fix editor losing focus after first word on Android. (facebookarchive#907)
* Fix editor losing focus after first word on Android. This patch narrows the scope of `restoreEditorDOM` to only blow away the `DraftEditorContents` instead of the entire editor. The key difference is that the `contentEditable` DOM element is not replaced, which means that the soft keyboard isn't dismissed on Android. Manually tested against "Cut" and "IME" tests: https://github.com/facebook/draft-js/wiki/Manual-Testing#cutcopypaste https://github.com/facebook/draft-js/wiki/Manual-Testing#ime Fixes facebookarchive#888, Ref facebookarchive#626, Ref facebookarchive#102 * Fix editor losing focus after first word on Android. This patch narrows the scope of `restoreEditorDOM` to only blow away the `DraftEditorContents` instead of the entire editor. The key difference is that the `contentEditable` DOM element is not replaced, which means that the soft keyboard isn't dismissed on Android. Manually tested against "Cut" and "IME" tests: https://github.com/facebook/draft-js/wiki/Manual-Testing#cutcopypaste https://github.com/facebook/draft-js/wiki/Manual-Testing#ime Fixes facebookarchive#888, Ref facebookarchive#626, Ref facebookarchive#102
1 parent 56590ef commit d6cad2e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/component/base/DraftEditor.react.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const handlerMap = {
5757
};
5858

5959
type State = {
60-
containerKey: number,
60+
contentsKey: number,
6161
};
6262

6363
/**
@@ -171,7 +171,7 @@ class DraftEditor extends React.Component {
171171
this.onDragLeave = this._onDragLeave.bind(this);
172172

173173
// See `_restoreEditorDOM()`.
174-
this.state = {containerKey: 0};
174+
this.state = {contentsKey: 0};
175175
}
176176

177177
/**
@@ -230,7 +230,6 @@ class DraftEditor extends React.Component {
230230
{this._renderPlaceholder()}
231231
<div
232232
className={cx('DraftEditor/editorContainer')}
233-
key={'editor' + this.state.containerKey}
234233
ref="editorContainer">
235234
<div
236235
aria-activedescendant={
@@ -283,6 +282,7 @@ class DraftEditor extends React.Component {
283282
customStyleFn={this.props.customStyleFn}
284283
editorKey={this._editorKey}
285284
editorState={this.props.editorState}
285+
key={'contents' + this.state.contentsKey}
286286
/>
287287
</div>
288288
</div>
@@ -383,13 +383,14 @@ class DraftEditor extends React.Component {
383383
/**
384384
* Used via `this.restoreEditorDOM()`.
385385
*
386-
* Force a complete re-render of the editor based on the current EditorState.
387-
* This is useful when we know we are going to lose control of the DOM
388-
* state (cut command, IME) and we want to make sure that reconciliation
389-
* occurs on a version of the DOM that is synchronized with our EditorState.
386+
* Force a complete re-render of the DraftEditorContents based on the current
387+
* EditorState. This is useful when we know we are going to lose control of
388+
* the DOM state (cut command, IME) and we want to make sure that
389+
* reconciliation occurs on a version of the DOM that is synchronized with
390+
* our EditorState.
390391
*/
391392
_restoreEditorDOM(scrollPosition?: DraftScrollPosition): void {
392-
this.setState({containerKey: this.state.containerKey + 1}, () => {
393+
this.setState({contentsKey: this.state.contentsKey + 1}, () => {
393394
this._focus(scrollPosition);
394395
});
395396
}

0 commit comments

Comments
 (0)