From 2e221caf837d465f0d3af6239f59bfcb66f6abd8 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 26 Feb 2019 05:33:48 +0100 Subject: [PATCH] Fix RichTextInput does not update when content is changed outside the editor Closes #2464 --- packages/ra-input-rich-text/src/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/ra-input-rich-text/src/index.js b/packages/ra-input-rich-text/src/index.js index d214a410256..da6c41d8ef4 100644 --- a/packages/ra-input-rich-text/src/index.js +++ b/packages/ra-input-rich-text/src/index.js @@ -49,6 +49,18 @@ export class RichTextInput extends Component { this.quill.on('text-change', debounce(this.onTextChange, 500)); } + componentDidUpdate(prevProps) { + if (prevProps.input.value !== this.props.input.value) { + const selection = this.quill.getSelection(); + this.quill.setContents( + this.quill.clipboard.convert(this.props.input.value) + ); + if (selection && this.quill.hasFocus()) { + this.quill.setSelection(selection); + } + } + } + componentWillUnmount() { this.quill.off('text-change', this.onTextChange); this.quill = null;