Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

reactjs - Styling not being applied to contentBlock in Draft.Js

I am attempting to change block type of the content block. The way I do this is by copying Notions UX and have a menu open when the user presses "/". From there they can select a option in the list i.e H1 Heading.

Using an "OnMouseDown" function, it triggers a parent function which is this:

    function changeBlockType(type: string) {
        const newEditorState = RichUtils.toggleBlockType(editorState, type);
        
        if (newEditorState) {
            setEditorState(newEditorState);
        }
    }

I am using functional components, so this changes the editorState.

When I console.log the current content block and inspect, I can find that the block type has been changed (type is now "H1 Heading"):

0: Array [ "key", "fkj5e" ]
????
1: Array [ "text", "/" ]
????
2: Array [ "type", "H1 Heading" ]
????
3: Array [ "characterList", {…} ]

But no actual styling is applied on the editor. The text styling remains the same.

question from:https://stackoverflow.com/questions/65916424/styling-not-being-applied-to-contentblock-in-draft-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...