react-quill icon indicating copy to clipboard operation
react-quill copied to clipboard

The onChange event is triggered event at the wrong moment

Open nisiah78 opened this issue 1 year ago • 2 comments

I use modal to "edit" or "add" content with rich text, edit means the content already exist and add means to add new content. when i want to edit content, the onChange event is already triggered when i open the modal box that will be my editor and here comes the issue, because the previous state will be applied to the new content that i am going to edit.

i did add onKeyUp but it doesn't work with mouse event

Here is my code

<ReactQuill id='description-en' theme='snow' className='' value={news?.description ?? ''} onChange={(content, delta, source, editor) => { if (editor.getLength() > 1 && Object.keys(news).length > 0) { setNews({ ...news, description: editor.getHTML() }); } }} onKeyUp={(event) => { if (news) setNews({ ...news, description: event.target.innerHTML, }); }} />

nisiah78 avatar Dec 15 '22 10:12 nisiah78

Any workaround so far? Facing same issue

erpardeepjain avatar Jan 24 '23 12:01 erpardeepjain

I had the same problem. The "onChange" event only trigger when space key is pressed. In my case, it solve passing keyUp prop:

<ReactQuill
  ref={ref}
  modules={mods}
  theme="snow"
  value={value}
  onKeyUp={() => ref.current?.getEditor().getSelection()}
  onChange={onChange}
  onBlur={onBlur}
/>

prrrcl avatar Apr 22 '23 15:04 prrrcl