There is no way to disable undo
See original GitHub issueDo you want to request a feature or report a bug? Documentation error and missing function.
What is the current behavior? The documentation says you should not modify the allowUndo property directly, but instead use the provided static and instance functions. There is not an instance function which allows you to set allowUndo.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar. The source code says that the _immutable property of the editor state is private and should not be modified, but since there is no other way to do this, thankfully the editor state is just an instance property and can be modified and set.
editorState._immutable = editorState._immutable.set('allowUndo', false);
This is currently the only way to set allowUndo and it’s no bueno. Overwriting a private instance property from outside like this is an anti-pattern.
What is the expected behavior? There should be an instance function to change allowUndo.
Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js? All of them.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:16 (3 by maintainers)
Update on this, to accomplish this behaviour, one needs to do the following:
This solution works!
You seem to mutate the already created “editorState”. Instead, return a new “editorState” using the “EditorState” static setter with the new config. As the immutable pattern is intended ;P
Like this
You can also do it when creating the editorState using the static method: https://facebook.github.io/draft-js/docs/api-reference-editor-state.html#create