fix(richtext-lexical): open inline block drawer on mount (#10318)

fix #9816
This commit is contained in:
Germán Jabloñski
2025-01-03 13:54:46 -03:00
committed by GitHub
parent f2fab39d67
commit 5997aa1c69

View File

@@ -81,6 +81,7 @@ export const InlineBlockComponent: React.FC<Props> = (props) => {
} = useEditorConfigContext()
const { getFormState } = useServerFunctions()
const editDepth = useEditDepth()
const hasMounted = useRef(false)
const [initialState, setInitialState] = React.useState<false | FormState | undefined>(
initialLexicalFormState?.[formData.id]?.formState,
@@ -116,6 +117,15 @@ export const InlineBlockComponent: React.FC<Props> = (props) => {
const clientBlock = blocksField.blocks[0]
// Open drawer on mount
useEffect(() => {
// > 2 because they always have "id" and "blockName" fields
if (!hasMounted.current && clientBlock.fields.length > 2) {
toggleDrawer()
hasMounted.current = true
}
}, [clientBlock, toggleDrawer])
const removeInlineBlock = useCallback(() => {
editor.update(() => {
$getNodeByKey(nodeKey)?.remove()