diff --git a/packages/react/src/editor/BlockNoteView.tsx b/packages/react/src/editor/BlockNoteView.tsx index b037a7d26c..4f44d9b262 100644 --- a/packages/react/src/editor/BlockNoteView.tsx +++ b/packages/react/src/editor/BlockNoteView.tsx @@ -163,7 +163,6 @@ function BlockNoteViewComponent< className, editorColorScheme, contentEditableProps, - ref, ...rest, }; @@ -176,7 +175,7 @@ function BlockNoteViewComponent< }}> {renderEditor ? ( - {children} + {children} ) : ( children )} @@ -199,73 +198,82 @@ export const BlockNoteViewRaw = React.forwardRef(BlockNoteViewComponent) as < /** * Renders the editor itself and the default UI elements */ -export const BlockNoteViewEditor = (props: { children: ReactNode }) => { - const ctx = useBlockNoteViewContext()!; - const editor = useBlockNoteEditor(); +export const BlockNoteViewEditor = React.forwardRef( + (props: { children: ReactNode }, ref: React.Ref) => { + const ctx = useBlockNoteViewContext()!; + const editor = useBlockNoteEditor(); - const portalManager = useMemo(() => { - return getContentComponent(); - }, []); + const portalManager = useMemo(() => { + return getContentComponent(); + }, []); - const mount = useCallback( - (element: HTMLElement | null) => { - editor.mount(element, portalManager); - }, - [editor, portalManager] - ); + const mount = useCallback( + (element: HTMLElement | null) => { + editor.mount(element, portalManager); + }, + [editor, portalManager] + ); - return ( - <> - - - {/* Renders the UI elements such as formatting toolbar, etc, unless they have been explicitly disabled in defaultUIProps */} - - {/* Manually passed in children, such as customized UI elements / controllers */} - {props.children} - - - ); -}; + return ( + <> + + + {/* Renders the UI elements such as formatting toolbar, etc, unless they have been explicitly disabled in defaultUIProps */} + + {/* Manually passed in children, such as customized UI elements / controllers */} + {props.children} + + + ); + } +); /** * Renders the container div + contentEditable div. */ -const EditorElement = ( - props: { - className?: string; - editorColorScheme?: string; - autoFocus?: boolean; - mount: (element: HTMLElement | null) => void; - contentEditableProps?: Record; - children: ReactNode; - ref?: React.Ref; - } & HTMLAttributes -) => { - const { - className, - editorColorScheme, - autoFocus, - mount, - children, - contentEditableProps, - ...rest - } = props; - return ( - // The container wraps the contentEditable div and UI Elements such as sidebar, formatting toolbar, etc. -
- {/* The actual contentEditable that Prosemirror mounts to */} +const EditorElement = React.forwardRef( + ( + props: { + className?: string; + editorColorScheme?: string; + autoFocus?: boolean; + mount: (element: HTMLElement | null) => void; + contentEditableProps?: Record; + children: ReactNode; + } & HTMLAttributes, + ref: React.Ref + ) => { + const { + className, + editorColorScheme, + autoFocus, + mount, + children, + contentEditableProps, + ...rest + } = props; + return ( + // The container wraps the contentEditable div and UI Elements such as sidebar, formatting toolbar, etc.
- {/* The UI elements such as sidebar, formatting toolbar, etc. */} - {children} -
- ); -}; + className={mergeCSSClasses( + "bn-container", + editorColorScheme, + className + )} + data-color-scheme={editorColorScheme} + {...rest} + ref={ref}> + {/* The actual contentEditable that Prosemirror mounts to */} +
+ {/* The UI elements such as sidebar, formatting toolbar, etc. */} + {children} +
+ ); + } +);