Last active
September 29, 2018 20:38
-
-
Save tonis2/cfeb6d044347d6f3cbab656d6a94eee2 to your computer and use it in GitHub Desktop.
draft.js remove styles and block-type from selection
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
clear() { | |
const {editorState} = this.state | |
const selection = editorState.getSelection() | |
const contentState = editorState.getCurrentContent() | |
const styles = editorState.getCurrentInlineStyle() | |
const removeStyles = styles.reduce((state, style) => { | |
return Modifier.removeInlineStyle(state, selection, style) }, contentState) | |
const removeBlock = Modifier.setBlockType(removeStyles, selection, 'unstyled') | |
this.setState({ | |
editorState: EditorState.push( | |
editorState, | |
removeBlock | |
) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: It seems
const styles = editorState.getCurrentInlineStyle()
doesn't return anything if the selection spans blocks.