Bug - clearing editorState when blurred doesn't work
See original GitHub issueHello, when I tried to use onBlur handler bellow, it doesn’t work and I have no idea why. Otherwise editor works OK, I use the latest version.
Note that:
- yes, the method runs after user blur from editor (and handleBlur is binded to this in contructor)
- it also passes through my condition, so the actual code inside runs
- it triggers another re-render of component after that, but the editorState is not changed
handleBlur() {
const { resetTextOnBlur, text } = this.props;
// reset editor to previous value in props
if (resetTextOnBlur) {
let editorState = EditorState.push(this.state.editorState, ContentState.createFromText(text));
this.setState({ editorState });
}
}
render() {
const { placeholder } = this.props;
return (
<Editor
name="message"
editorState={this.state.editorState}
keyBindingFn={this.myKeyBindingFn}
onChange={this.onChange}
onBlur={this.handleBlur}
ref="editor"
placeholder={placeholder}
/>
);
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
Detect blur aka losing focus of a Draft.js editor - Stack Overflow
Is there a "correct way" to detect if I lose focus of a Draft.js editor? The use case is, that I want "quit...
Read more >FIXED: Youtube Blur Effect Won't Save
You spent hours on adding blur effects to your video then nothing happens when you click save and all the time you spend...
Read more >NodeView selection is lost if div.ProseMirror is altered on tab ...
I'm encountering some other bugs where nodeselections are lost when blurring the view as well. Do you have any ideas for why, on...
Read more >BUG : Writing Text with the Pen Code makes it blur away
It does this in the full screen mode, on the public version of the code, and in full screen in the Editor. Yet...
Read more >23440 - Wrong text-shadow blur rendering - chromium
An acknowledged and year-and-a-half old bug, would be nice to see fixed. ... Also, very importantly, the if you don't blur the text,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much guys! The solution is listen to getHasFocus() in onChange handler as @JohnONeill suggested. So this way, it works!
@calic39 Maybe you could just listen to the selection state’s
getHasFocus()
– when it’s false, you know the editor’s blurred, and you can listen to that / restore the original text within yourhandleChange()
handler:https://jsfiddle.net/9xvLqgka/4/ (just added a line of logging around the selection state
handleChange()
)