Skip to content

Commit 60ceeb0

Browse files
authored
fix(richtext-*): field errors and descriptions were not displayed (#9824)
1 parent dc741bb commit 60ceeb0

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

packages/richtext-lexical/src/field/Field.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
import type { EditorState, SerializedEditorState } from 'lexical'
33
import type { Validate } from 'payload'
44

5-
import { FieldLabel, useEditDepth, useField, withCondition } from '@payloadcms/ui'
5+
import {
6+
FieldDescription,
7+
FieldError,
8+
FieldLabel,
9+
RenderCustomComponent,
10+
useEditDepth,
11+
useField,
12+
withCondition,
13+
} from '@payloadcms/ui'
614
import { mergeFieldStyles } from '@payloadcms/ui/shared'
715
import React, { useCallback, useMemo } from 'react'
816
import { ErrorBoundary } from 'react-error-boundary'
917

1018
import type { SanitizedClientEditorConfig } from '../lexical/config/types.js'
1119
import type { LexicalRichTextFieldProps } from '../types.js'
1220

13-
import { LexicalProvider } from '../lexical/LexicalProvider.js'
1421
import '../lexical/theme/EditorTheme.scss'
1522
import './bundled.css'
1623
import './index.scss'
24+
import { LexicalProvider } from '../lexical/LexicalProvider.js'
1725

1826
const baseClass = 'rich-text-lexical'
1927

@@ -27,7 +35,7 @@ const RichTextComponent: React.FC<
2735
field,
2836
field: {
2937
name,
30-
admin: { className, readOnly: readOnlyFromAdmin } = {},
38+
admin: { className, description, readOnly: readOnlyFromAdmin } = {},
3139
label,
3240
localized,
3341
required,
@@ -95,7 +103,10 @@ const RichTextComponent: React.FC<
95103

96104
return (
97105
<div className={classes} key={pathWithEditDepth} style={styles}>
98-
{Error}
106+
<RenderCustomComponent
107+
CustomComponent={Error}
108+
Fallback={<FieldError path={path} showError={showError} />}
109+
/>
99110
{Label || <FieldLabel label={label} localized={localized} required={required} />}
100111
<div className={`${baseClass}__wrap`}>
101112
<ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>
@@ -112,6 +123,10 @@ const RichTextComponent: React.FC<
112123
{AfterInput}
113124
</ErrorBoundary>
114125
{Description}
126+
<RenderCustomComponent
127+
CustomComponent={Description}
128+
Fallback={<FieldDescription description={description} path={path} />}
129+
/>
115130
</div>
116131
</div>
117132
)

packages/richtext-slate/src/field/RichText.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ import type { HistoryEditor } from 'slate-history'
66
import type { ReactEditor } from 'slate-react'
77

88
import { getTranslation } from '@payloadcms/translations'
9-
import { FieldLabel, useEditDepth, useField, useTranslation, withCondition } from '@payloadcms/ui'
9+
import {
10+
FieldDescription,
11+
FieldError,
12+
FieldLabel,
13+
RenderCustomComponent,
14+
useEditDepth,
15+
useField,
16+
useTranslation,
17+
withCondition,
18+
} from '@payloadcms/ui'
1019
import { mergeFieldStyles } from '@payloadcms/ui/shared'
1120
import { isHotkey } from 'is-hotkey'
1221
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
@@ -46,7 +55,7 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
4655
field,
4756
field: {
4857
name,
49-
admin: { className, placeholder, readOnly: readOnlyFromAdmin } = {},
58+
admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},
5059
label,
5160
required,
5261
},
@@ -307,7 +316,10 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
307316
<div className={classes} style={styles}>
308317
{Label || <FieldLabel label={label} required={required} />}
309318
<div className={`${baseClass}__wrap`}>
310-
{Error}
319+
<RenderCustomComponent
320+
CustomComponent={Error}
321+
Fallback={<FieldError path={path} showError={showError} />}
322+
/>
311323
<Slate
312324
editor={editor}
313325
key={JSON.stringify({ initialValue, path })} // makes sure slate is completely re-rendered when initialValue changes, bypassing the slate-internal value memoization. That way, external changes to the form will update the editor
@@ -438,7 +450,10 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
438450
</div>
439451
</div>
440452
</Slate>
441-
{Description}
453+
<RenderCustomComponent
454+
CustomComponent={Description}
455+
Fallback={<FieldDescription description={description} path={path} />}
456+
/>
442457
</div>
443458
</div>
444459
)

0 commit comments

Comments
 (0)