From d36c72c435060a913f9c0045b4f572cc2e42d882 Mon Sep 17 00:00:00 2001 From: Guilherme Minozzi Date: Mon, 24 Jul 2023 04:03:54 -0300 Subject: [PATCH] fix: don't show `canvasBackground` label when `UIOptions.canvasActions.changeViewBackgroundColor` is false (#6781) * fix(components/main-menu): not show canvasBackground * chore(components/main-menu): add data-testid attr to canvasBackground label * test(tests/packages/excalidraw): check whether canvasbackground label is rendered when changeviewbackground is false * test: update snapshots * fix(tests/packages/excalidraw): change to lowercase canvas background test id * change to pull request target for size-limit * Revert "change to pull request target for size-limit" This reverts commit baf1ca2677be4b51c6666522387ab9da9ac9f9d1. * Add test --------- Co-authored-by: Aakansha Doshi --- src/components/main-menu/DefaultItems.tsx | 12 ++++++++++-- src/packages/excalidraw/example/App.tsx | 6 +++++- .../__snapshots__/excalidraw.test.tsx.snap | 1 + src/tests/packages/excalidraw.test.tsx | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/main-menu/DefaultItems.tsx b/src/components/main-menu/DefaultItems.tsx index 919443d12..2908d6b47 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 7f17b292f..8240de887 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 4caa6c6dd..d026b21ef 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 91fd9c09f..069f9c000 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(); });