Skip to content

Instantly share code, notes, and snippets.

@tonis2
Last active September 29, 2018 20:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonis2/cfeb6d044347d6f3cbab656d6a94eee2 to your computer and use it in GitHub Desktop.
Save tonis2/cfeb6d044347d6f3cbab656d6a94eee2 to your computer and use it in GitHub Desktop.
draft.js remove styles and block-type from selection
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
)
})
}
@calebbrewer
Copy link

I've been looking for this! Thanks!

@blainegarrett
Copy link

Note: It seems const styles = editorState.getCurrentInlineStyle() doesn't return anything if the selection spans blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment