Skip to content

Commit c4bbd17

Browse files
author
gjulivan
committed
fix: update string attribute also update rte content
1 parent 423c66f commit c4bbd17

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

packages/pluggableWidgets/rich-text-web/src/RichText.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
21
import classNames from "classnames";
32
import { Fragment, ReactElement } from "react";
3+
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
44
import { RichTextContainerProps } from "../typings/RichTextProps";
55
import EditorWrapper from "./components/EditorWrapper";
66
import "./ui/RichText.scss";
77

88
export default function RichText(props: RichTextContainerProps): ReactElement {
99
const { stringAttribute } = props;
10-
1110
return (
1211
<Fragment>
1312
{stringAttribute.status === "loading" ? (

packages/pluggableWidgets/rich-text-web/src/components/Editor.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TaskList } from "@tiptap/extension-task-list";
88
import { TextStyle } from "@tiptap/extension-text-style";
99
import { EditorContent, useEditor } from "@tiptap/react";
1010
import { StarterKit } from "@tiptap/starter-kit";
11-
import { forwardRef, ReactElement, useImperativeHandle, useMemo } from "react";
11+
import { forwardRef, ReactElement, useEffect, useImperativeHandle, useMemo } from "react";
1212
import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action";
1313
import { EditorContextProvider, useCurrentEditor } from "./EditorContext";
1414
import { HighlightedCodeEditor } from "./HighlightedCodeEditor";
@@ -275,6 +275,18 @@ const Editor = forwardRef<EditorHandle, EditorProps>((props, ref) => {
275275
getEditor: () => editor
276276
}));
277277

278+
// update quills content on value change.
279+
useEffect(() => {
280+
// if there is an update comes from external element (default value sudden change)
281+
// only do update if editor not focused, otherwise it will override the user input.
282+
if (!editor.isFocused) {
283+
const newContent = editor.getHTML();
284+
if (newContent && newContent !== defaultValue) {
285+
editor.commands.setContent(defaultValue || "");
286+
}
287+
}
288+
}, [editor, defaultValue]);
289+
278290
if (!editor) {
279291
return null;
280292
}

0 commit comments

Comments
 (0)