this.setState({editorState: EditorState.createEmpty()}) doesn't work to clear the component #73
Comments
Did you mean to do |
Sorry, the title is incorrect. I did |
I can't get this to repro. I used the Do you have some sample code to share? |
I cleared on |
Did you return http://facebook.github.io/draft-js/docs/api-reference-editor.html#cancelable-handlers-optional |
Yes, I returned true and then cleared the input. Upon subsequent typing it seemed like my newline was latently sitting there waiting for more text. |
Can you provide a gist? |
Hello! I'm experiencing this issue too. Here is the gist: After pressing escape or enter, the editor is cleared, but when I press a letter key, it adds a letter after the cursor, not before. And after pressing a letter key second time, it creates a new line with previous key. It produces this html: https://gist.github.com/Ahineya/bb4556ae3e5503ce1ddf And after pressing enter or escape, produced html is like this: And when new line is created, pressing escape or enter doesn't remove it.
|
Thanks, this helps give me a hunch about what the issue is here. When using As you note, using I think the right fix here is to create an static createEmptyWithFocus() {
const empty = EditorState.createEmpty();
return EditorState.moveFocusToEnd(empty);
} Does that sound like a good solution to you? |
Yes. Any chance you could log a warning if createEmpty is called and the On Wed, Mar 2, 2016 at 11:44 AM Isaac Salier-Hellendag <
|
Hmm, it's hard to say where exactly the warning would go. Within a |
Would love a PR for this, with or without a console warning. :) |
Yes, thank you. I have understand that this is by-design stuff :) |
|
This was great. I feel like this should be in an FAQ somewhere. Clearing the editor should be a pretty common use case. |
With this method, the editor seems to get its internal state corrupted.
EditorState.moveFocusToEnd(EditorState.createEmpty())
was required to actually clear the state properly.The text was updated successfully, but these errors were encountered: