Skip to content

Commit 4bb2d64

Browse files
committed
Disabled default UI when no components context is found
1 parent a850078 commit 4bb2d64

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
@@ -30,6 +30,7 @@ import {
3030
BlockNoteViewContext,
3131
useBlockNoteViewContext,
3232
} from "./BlockNoteViewContext.js";
33+
import { useComponentsContext } from "./ComponentsContext.js";
3334
import { Portals, getContentComponent } from "./EditorContent.js";
3435
import { ElementRenderer } from "./ElementRenderer.js";
3536

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

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

@@ -167,30 +195,9 @@ function BlockNoteViewComponent<
167195
contentEditableProps,
168196
editable,
169197
},
170-
defaultUIProps: {
171-
formattingToolbar,
172-
linkToolbar,
173-
slashMenu,
174-
emojiPicker,
175-
sideMenu,
176-
filePanel,
177-
tableHandles,
178-
comments,
179-
},
198+
defaultUIProps,
180199
};
181-
}, [
182-
autoFocus,
183-
contentEditableProps,
184-
editable,
185-
formattingToolbar,
186-
linkToolbar,
187-
slashMenu,
188-
emojiPicker,
189-
sideMenu,
190-
filePanel,
191-
tableHandles,
192-
comments,
193-
]);
200+
}, [autoFocus, contentEditableProps, editable, defaultUIProps]);
194201

195202
return (
196203
<BlockNoteContext.Provider value={blockNoteContext}>

0 commit comments

Comments
 (0)