Reputation: 59
I want to add some buttons like save and cancel . How to do that ? similar like teams where we can edit our comments on click of save and cancel?
Add onBlur={this.updateComment.bind(this)}
event to do save comments in editor but want to implement buttons like below
<Editor
editorState={editorState}
wrapperClassName="demo-wrapper"
onEditorStateChange={this.onEditorStateChange}
onBlur={this.updateComment.bind(this)}
}}
/>
Upvotes: 0
Views: 873
Reputation: 19
add the trigger and buttons independently on them, move onBlur to the wrapper element (shared one) if you didn't get it then look at the code
<div onBlur={onSave}>
<Editor editorState={editorState} onEditorStateChange={onChange} />
<div className="buttons">
<span className="status">{saveState}</span>
<button className="button" onClick={onCancel}>
X
</button>
<button className="button" onClick={onSave}>
V
</button>
</div>
</div>
Upvotes: -1
Reputation: 1634
You need to add the buttons independently and trigger the events on them.
Then you need to move the onBlur to the shared wrapper element and it will work as expected.
In the below example you can see:
<div onBlur={onSave}>
<Editor editorState={editorState} onEditorStateChange={onChange} />
<div className="buttons">
<span className="status">{saveState}</span>
<button className="button" onClick={onCancel}>
X
</button>
<button className="button" onClick={onSave}>
V
</button>
</div>
</div>
Here is a codesandbox example: https://codesandbox.io/s/react-draft-wysiwyg-with-save-and-cancel-xoxr3f?file=/src/EditorWithButtons.jsx
Upvotes: 1