Skip to content

fix: Mantine CSS variables element #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/mantine/src/BlockNoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,27 @@ export const BlockNoteView = <
[defaultColorScheme, theme]
);

const finalTheme =
typeof theme === "string"
? theme
: defaultColorScheme !== "no-preference"
? defaultColorScheme
: "light";

return (
<ComponentsContext.Provider value={components}>
{/* `cssVariablesSelector` scopes Mantine CSS variables to only the editor, */}
{/* as proposed here: https://github.com/orgs/mantinedev/discussions/5685 */}
<MantineProvider
theme={mantineTheme}
// Scopes Mantine CSS variables to only the editor, as proposed here:
// https://github.com/orgs/mantinedev/discussions/5685
cssVariablesSelector=".bn-mantine"
// This gets the element to set `data-mantine-color-scheme` on. Since we
// don't need this attribute (we use our own theming API), we return
// undefined here.
// This gets the element to set `data-mantine-color-scheme` on. This
// element needs to already be rendered, so we can't set it to the
// editor container element. Instead, we set it to `undefined` and set it
// manually in `BlockNoteViewRaw`.
getRootElement={() => undefined}>
<BlockNoteViewRaw
data-mantine-color-scheme={finalTheme}
className={mergeCSSClasses("bn-mantine", className || "")}
theme={typeof theme === "object" ? undefined : theme}
{...rest}
Expand Down
Loading