Skip to content

Commit aab6e54

Browse files
matthewlipskinperez0111
authored andcommitted
Disabled default UI when no components context is found
1 parent 4bfa458 commit aab6e54

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

packages/react/src/editor/BlockNoteView.tsx

Lines changed: 30 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,33 @@ 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:
147+
formattingToolbar ?? (componentsContext ? undefined : false),
148+
linkToolbar: linkToolbar ?? (componentsContext ? undefined : false),
149+
sideMenu: sideMenu ?? (componentsContext ? undefined : false),
150+
slashMenu: slashMenu ?? (componentsContext ? undefined : false),
151+
filePanel: filePanel ?? (componentsContext ? undefined : false),
152+
tableHandles: tableHandles ?? (componentsContext ? undefined : false),
153+
emojiPicker: emojiPicker ?? (componentsContext ? undefined : false),
154+
comments: comments ?? (componentsContext ? undefined : false),
155+
}),
156+
[
157+
comments,
158+
componentsContext,
159+
emojiPicker,
160+
filePanel,
161+
formattingToolbar,
162+
linkToolbar,
163+
sideMenu,
164+
slashMenu,
165+
tableHandles,
166+
],
167+
);
168+
141169
useEditorChange(onChange || emptyFn, editor);
142170
useEditorSelectionChange(onSelectionChange || emptyFn, editor);
143171

@@ -180,30 +208,9 @@ function BlockNoteViewComponent<
180208
contentEditableProps,
181209
editable,
182210
},
183-
defaultUIProps: {
184-
formattingToolbar,
185-
linkToolbar,
186-
slashMenu,
187-
emojiPicker,
188-
sideMenu,
189-
filePanel,
190-
tableHandles,
191-
comments,
192-
},
211+
defaultUIProps,
193212
};
194-
}, [
195-
autoFocus,
196-
contentEditableProps,
197-
editable,
198-
formattingToolbar,
199-
linkToolbar,
200-
slashMenu,
201-
emojiPicker,
202-
sideMenu,
203-
filePanel,
204-
tableHandles,
205-
comments,
206-
]);
213+
}, [autoFocus, contentEditableProps, editable, defaultUIProps]);
207214

208215
return (
209216
<BlockNoteContext.Provider value={blockNoteContext}>

0 commit comments

Comments
 (0)