Skip to content

Commit f037bb3

Browse files
committed
fix: fixed onChange and validate
1 parent d075aac commit f037bb3

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

demo/src/fields/debugLexicalRichTextField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function lexicalRichText(props?: { name?: string; label?: string; debug?: boolea
3131
name: props?.name ? props?.name : 'lexical_richtext',
3232
label: props?.label ? props?.label : 'Rich Text',
3333
localized: true,
34+
required: true,
3435
editorConfigModifier: (defaultEditorConfig) => {
3536
defaultEditorConfig.debug = props?.debug ? props?.debug : false;
3637
defaultEditorConfig.toggles.textColor.enabled = true;

src/fields/LexicalRichText/FieldComponent.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const FieldComponent: React.FC<Props> = (props) => {
7878
}>({
7979
path, // required
8080
validate: memoizedValidate,
81-
condition,
81+
condition: condition ?? undefined,
8282
});
8383

8484
// Here is what `useField` sends back
@@ -126,22 +126,28 @@ const FieldComponent: React.FC<Props> = (props) => {
126126
}}
127127
>
128128
<EditorProviders
129+
initialJSON={getJsonContentFromValue(value)}
130+
editorConfig={editorConfig}
131+
initialComments={value?.comments}
132+
value={value}
133+
setValue={setValue}
129134
onChange={(
130135
editorState: EditorState,
131136
editor: LexicalEditor,
132137
tags: Set<string>,
133138
commentStore: CommentStore
134139
) => {
135140
const json = editorState.toJSON();
136-
const valueJsonContent = getJsonContentFromValue(value);
141+
// const valueJsonContent = getJsonContentFromValue(value);
137142
// TODO: Wondering why the deepEqual was here since if we set
138143
// ignoreSelectionChange={true} in our OnChangePlugin instances
139144
// - a call here means that something _must_ have changed - and so
140145
// not sure that we need to do any comparison at all?
141146
// TODO: Revisit if neccessary, but Lexical confirmed that ignoreSelectionChange={true}
142147
// should be fine in this case, and so we don't need to deepEqual and can trust
143148
// that an onChange event here means 'something' actually changed.
144-
if (!(readOnly ?? false) && valueJsonContent != null) {
149+
// if (!(readOnly ?? false) && valueJsonContent != null) {
150+
if (!(readOnly ?? false)) {
145151
const textContent = editor.getEditorState().read(() => {
146152
return $getRoot().getTextContent();
147153
});
@@ -174,11 +180,6 @@ const FieldComponent: React.FC<Props> = (props) => {
174180
});
175181
}
176182
}}
177-
initialJSON={getJsonContentFromValue(value)}
178-
editorConfig={editorConfig}
179-
initialComments={value?.comments}
180-
value={value}
181-
setValue={setValue}
182183
/>
183184
<FieldDescription value={value} description={description} />
184185
</ErrorBoundary>

0 commit comments

Comments
 (0)