Please help me figure it out. I want to style the elements on both the output and the input.
How do I style unstyled elements and my custom components?
For example, I have a custom_btn entity, and a button. When you click on which the word is stylized. After the structure looks like this
const data = <p class ="article_paragraph"> <div class ="custom_btn"> 123 </div></p>;
But when I give this structure to draftjs (simulate data loading), for some reason I get
const data=<p class="article_paragraph">123 </p>;
Here's another example with bold text. I expect draftjs to get the structure
<p class = "article_paragraph"> <span class = "custom_bold"> 123 </span> </p>
will make the text bold.
But in fact, draftjs trims to <p class = "article_paragraph"> 123 </p>
For clarity, I created an example on codesanbox
I spent a lot of time, but I couldn't figure it out. Help me please.
Editor file
//The problem is here. I expect to see the result as when clicking on CUSTOM BTN OR BOLD BTN
const data = `<p class="article_paragraph"><span class="custom_bold">SOME BOLD TEXT</span></p>
<p class="article_paragraph"><div class="custom_btn">AND CUSTOM BTN </div></p>`;
// but i see this
/*<p class="article_paragraph">SOME BOLD TEXT</p>
<p class="article_paragraph">AND CUSTOM BTN </p> */
export default function CustomEditor() {
const [editorState, setEditorState] = useState(
EditorState.createWithContent(stateFromHTML(data), decorator)
);
return (
<div className="CustomEditor">
<Tollbar editorState={editorState} onChange={setEditorState} />
<Editor
editorState={editorState}
onChange={editorState => setEditorState(editorState)}
/>
<textarea
disabled
style={{ width: 800, height: 300, marginTop: 20 }}
value={stateToHTML(editorState.getCurrentContent(), getOptions())}
/>
</div>
);
}
Hello. Thank you so much for your work.
Please help me figure it out. I want to style the elements on both the output and the input.
How do I style unstyled elements and my custom components? For example, I have a custom_btn entity, and a button. When you click on which the word is stylized. After the structure looks like this
const data = <p class ="article_paragraph"> <div class ="custom_btn"> 123 </div></p>;
But when I give this structure to draftjs (simulate data loading), for some reason I get
const data=<p class="article_paragraph">123 </p>;
Here's another example with bold text. I expect draftjs to get the structure
<p class = "article_paragraph"> <span class = "custom_bold"> 123 </span> </p>
will make the text bold.But in fact, draftjs trims to
<p class = "article_paragraph"> 123 </p>
For clarity, I created an example on codesanboxI spent a lot of time, but I couldn't figure it out. Help me please.
Editor file
Toolbar
Decorators