facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.57k stars 2.64k forks source link

How to get styles of focused text or content #2109

Open JMA12 opened 5 years ago

JMA12 commented 5 years ago

editor

How can I get the inline styles that focused content have?

For instance, the focused text as shown on the image is bold.

jobpaardekooper commented 5 years ago

You can get an array of the current inline styles by doing the following.

const inlineStyles = editorState.getCurrentInlineStyle();

As written in the documentation.

Thanks to @jkhaui for the correction.

jkhaui commented 5 years ago

@jobpaardekooper Just a heads up, you don't pass any arguments to getCurrentInlineStyle() I'm pretty sure. So just using const inlineStyles = editorState.getCurrentInlineStyle(); on its own is enough to return an OrderedSet which holds the inline styling info

jobpaardekooper commented 5 years ago

@jkhaui you are correct according to the documentation.