Skip to content

Commit de956e8

Browse files
fix: disable default UI when no components context is found (#2611)
1 parent d8fb6c2 commit de956e8

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

packages/react/src/editor/BlockNoteView.tsx

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
BlockNoteViewContext,
3232
useBlockNoteViewContext,
3333
} from "./BlockNoteViewContext.js";
34+
import { useComponentsContext } from "./ComponentsContext.js";
3435
import { Portals, getContentComponent } from "./EditorContent.js";
3536
import { ElementRenderer } from "./ElementRenderer.js";
3637

@@ -138,6 +139,32 @@ function BlockNoteViewComponent<
138139
const editorColorScheme =
139140
theme || (defaultColorScheme === "dark" ? "dark" : "light");
140141

142+
// Disable default UI components if no components context is found.
143+
const componentsContext = useComponentsContext();
144+
const defaultUIProps: BlockNoteDefaultUIProps = useMemo(
145+
() => ({
146+
formattingToolbar: componentsContext ? formattingToolbar : false,
147+
linkToolbar: componentsContext ? linkToolbar : false,
148+
sideMenu: componentsContext ? sideMenu : false,
149+
slashMenu: componentsContext ? slashMenu : false,
150+
filePanel: componentsContext ? filePanel : false,
151+
tableHandles: componentsContext ? tableHandles : false,
152+
emojiPicker: componentsContext ? emojiPicker : false,
153+
comments: componentsContext ? comments : false,
154+
}),
155+
[
156+
comments,
157+
componentsContext,
158+
emojiPicker,
159+
filePanel,
160+
formattingToolbar,
161+
linkToolbar,
162+
sideMenu,
163+
slashMenu,
164+
tableHandles,
165+
],
166+
);
167+
141168
useEditorChange(onChange || emptyFn, editor);
142169
useEditorSelectionChange(onSelectionChange || emptyFn, editor);
143170

@@ -180,30 +207,9 @@ function BlockNoteViewComponent<
180207
contentEditableProps,
181208
editable,
182209
},
183-
defaultUIProps: {
184-
formattingToolbar,
185-
linkToolbar,
186-
slashMenu,
187-
emojiPicker,
188-
sideMenu,
189-
filePanel,
190-
tableHandles,
191-
comments,
192-
},
210+
defaultUIProps,
193211
};
194-
}, [
195-
autoFocus,
196-
contentEditableProps,
197-
editable,
198-
formattingToolbar,
199-
linkToolbar,
200-
slashMenu,
201-
emojiPicker,
202-
sideMenu,
203-
filePanel,
204-
tableHandles,
205-
comments,
206-
]);
212+
}, [autoFocus, contentEditableProps, editable, defaultUIProps]);
207213

208214
return (
209215
<BlockNoteContext.Provider value={blockNoteContext}>

0 commit comments

Comments
 (0)