Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/enter-in-title-not-focusing' int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
tiberiuichim committed Oct 6, 2020
2 parents 1c862c6 + ef14eab commit a715f7c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/editor/SlateEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SlateEditor extends Component {
}

handleChange(value) {
if (!isEqual(value, this.props.value)) {
if (this.props.onChange && !isEqual(value, this.props.value)) {
this.props.onChange(value);
}
}
Expand All @@ -92,6 +92,17 @@ class SlateEditor extends Component {
}
}

/**
* This method exists because using directly the ReactEditor.focus method
* produces the issue: Enter key press in title block does not focus the newly
* created Slate Text block.
*/
focusEditorAsync = () => {
return Promise.resolve().then(() => {
ReactEditor.focus(this.state.editor);
});
};

componentDidMount() {
// watch the dom change
window.document.addEventListener(
Expand All @@ -101,7 +112,7 @@ class SlateEditor extends Component {

if (this.props.selected) {
if (!ReactEditor.isFocused(this.state.editor)) {
ReactEditor.focus(this.state.editor);
this.focusEditorAsync();
}
}
}
Expand All @@ -121,6 +132,8 @@ class SlateEditor extends Component {

if (!prevProps.selected && this.props.selected) {
if (!ReactEditor.isFocused(this.state.editor)) {
// TODO: should we use this.focusEditorAsync here too instead of the
// following line?
ReactEditor.focus(this.state.editor);
}
}
Expand Down

0 comments on commit a715f7c

Please sign in to comment.