diff --git a/src/components/main-menu/DefaultItems.tsx b/src/components/main-menu/DefaultItems.tsx index 919443d1..2908d6b4 100644 --- a/src/components/main-menu/DefaultItems.tsx +++ b/src/components/main-menu/DefaultItems.tsx @@ -4,6 +4,7 @@ import { useExcalidrawSetAppState, useExcalidrawActionManager, useExcalidrawElements, + useAppProps, } from "../App"; import { ExportIcon, @@ -198,13 +199,20 @@ export const ChangeCanvasBackground = () => { const { t } = useI18n(); const appState = useUIAppState(); const actionManager = useExcalidrawActionManager(); + const appProps = useAppProps(); - if (appState.viewModeEnabled) { + if ( + appState.viewModeEnabled || + !appProps.UIOptions.canvasActions.changeViewBackgroundColor + ) { return null; } return (
-
+
{t("labels.canvasBackground")}
diff --git a/src/packages/excalidraw/example/App.tsx b/src/packages/excalidraw/example/App.tsx index 7f17b292..8240de88 100644 --- a/src/packages/excalidraw/example/App.tsx +++ b/src/packages/excalidraw/example/App.tsx @@ -678,7 +678,11 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) { gridModeEnabled={gridModeEnabled} theme={theme} name="Custom name of drawing" - UIOptions={{ canvasActions: { loadScene: false } }} + UIOptions={{ + canvasActions: { + loadScene: false, + }, + }} renderTopRightUI={renderTopRightUI} onLinkOpen={onLinkOpen} onPointerDown={onPointerDown} diff --git a/src/tests/packages/__snapshots__/excalidraw.test.tsx.snap b/src/tests/packages/__snapshots__/excalidraw.test.tsx.snap index 4caa6c6d..d026b21e 100644 --- a/src/tests/packages/__snapshots__/excalidraw.test.tsx.snap +++ b/src/tests/packages/__snapshots__/excalidraw.test.tsx.snap @@ -516,6 +516,7 @@ exports[` Test UIOptions prop Test canvasActions should render menu style="margin-top: 0.5rem;" >
Canvas background diff --git a/src/tests/packages/excalidraw.test.tsx b/src/tests/packages/excalidraw.test.tsx index 91fd9c09..069f9c00 100644 --- a/src/tests/packages/excalidraw.test.tsx +++ b/src/tests/packages/excalidraw.test.tsx @@ -199,6 +199,23 @@ describe("", () => { ); //open menu toggleMenu(container); + expect(queryByTestId(container, "canvas-background-label")).toBeNull(); + expect(queryByTestId(container, "canvas-background-picker")).toBeNull(); + }); + + it("should hide the canvas background picker even if passed if the `canvasActions.changeViewBackgroundColor` is set to false", async () => { + const { container } = await render( + + + + + , + ); + //open menu + toggleMenu(container); + expect(queryByTestId(container, "canvas-background-label")).toBeNull(); expect(queryByTestId(container, "canvas-background-picker")).toBeNull(); });