Skip to content

Commit 4fd8d03

Browse files
swheeler7AlessioGr
andauthored
fix(richtext-lexical): bulk upload drawer rendered at the wrong depth if already in a drawer (#14472)
This wraps the Lexical editor in the BulkUploadProvider which matches the Upload Field. Now, when the lexical upload feature calls the useBulkUpload hook it has access to the correct edit depth. Alternative approaches might be to modify the BulkUploadProvider to pass in the depth directly but this seemed simplest and matches the Upload field. Fixes #14426 --------- Co-authored-by: Alessio Gravili <alessio@gravili.de>
1 parent 2bb5535 commit 4fd8d03

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { EditorState, SerializedEditorState } from 'lexical'
33

44
import {
5+
BulkUploadProvider,
56
FieldDescription,
67
FieldError,
78
FieldLabel,
@@ -181,16 +182,20 @@ const RichTextComponent: React.FC<
181182
<div className={`${baseClass}__wrap`}>
182183
<ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>
183184
{BeforeInput}
184-
<LexicalProvider
185-
composerKey={pathWithEditDepth}
186-
editorConfig={editorConfig}
187-
fieldProps={props}
188-
isSmallWidthViewport={isSmallWidthViewport}
189-
key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)
190-
onChange={handleChange}
191-
readOnly={disabled}
192-
value={value}
193-
/>
185+
{/* Lexical may be in a drawer. We need to define another BulkUploadProvider to ensure that the bulk upload drawer
186+
is rendered in the correct depth (not displayed *behind* the current drawer)*/}
187+
<BulkUploadProvider drawerSlugPrefix={path}>
188+
<LexicalProvider
189+
composerKey={pathWithEditDepth}
190+
editorConfig={editorConfig}
191+
fieldProps={props}
192+
isSmallWidthViewport={isSmallWidthViewport}
193+
key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)
194+
onChange={handleChange}
195+
readOnly={disabled}
196+
value={value}
197+
/>
198+
</BulkUploadProvider>
194199
{AfterInput}
195200
</ErrorBoundary>
196201
<RenderCustomComponent

0 commit comments

Comments
 (0)