Created
January 10, 2017 16:52
-
-
Save tomcask/6040f6695712df5d31645e48bda3fc2b to your computer and use it in GitHub Desktop.
Example of force selection in draftjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getEditorState = this.props.store.getItem('getEditorState'); | |
const setEditorState = this.props.store.getItem('setEditorState'); | |
const selection = this.props.store.getItem('lastSelection'); | |
const editorState = getEditorState(); | |
const updateSelection = new SelectionState({ | |
anchorKey: selection.anchorKey, | |
anchorOffset: selection.anchorOffset, | |
focusKey: selection.anchorKey, | |
focusOffset: selection.focusOffset, | |
isBackward: false, | |
}); | |
let newEditorState = EditorState.acceptSelection( | |
editorState, | |
updateSelection | |
); | |
newEditorState = EditorState.forceSelection(newEditorState, newEditorState.getSelection()); | |
setEditorState(newEditorState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sorry but I haven't used draftjs in a while, you'd have to do a test.