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 <aakansha1216@gmail.com>
This commit is contained in:
parent
e57dc405fa
commit
d36c72c435
@ -4,6 +4,7 @@ import {
|
|||||||
useExcalidrawSetAppState,
|
useExcalidrawSetAppState,
|
||||||
useExcalidrawActionManager,
|
useExcalidrawActionManager,
|
||||||
useExcalidrawElements,
|
useExcalidrawElements,
|
||||||
|
useAppProps,
|
||||||
} from "../App";
|
} from "../App";
|
||||||
import {
|
import {
|
||||||
ExportIcon,
|
ExportIcon,
|
||||||
@ -198,13 +199,20 @@ export const ChangeCanvasBackground = () => {
|
|||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const appState = useUIAppState();
|
const appState = useUIAppState();
|
||||||
const actionManager = useExcalidrawActionManager();
|
const actionManager = useExcalidrawActionManager();
|
||||||
|
const appProps = useAppProps();
|
||||||
|
|
||||||
if (appState.viewModeEnabled) {
|
if (
|
||||||
|
appState.viewModeEnabled ||
|
||||||
|
!appProps.UIOptions.canvasActions.changeViewBackgroundColor
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div style={{ marginTop: "0.5rem" }}>
|
<div style={{ marginTop: "0.5rem" }}>
|
||||||
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
|
<div
|
||||||
|
data-testid="canvas-background-label"
|
||||||
|
style={{ fontSize: ".75rem", marginBottom: ".5rem" }}
|
||||||
|
>
|
||||||
{t("labels.canvasBackground")}
|
{t("labels.canvasBackground")}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ padding: "0 0.625rem" }}>
|
<div style={{ padding: "0 0.625rem" }}>
|
||||||
|
@ -678,7 +678,11 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
|||||||
gridModeEnabled={gridModeEnabled}
|
gridModeEnabled={gridModeEnabled}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
name="Custom name of drawing"
|
name="Custom name of drawing"
|
||||||
UIOptions={{ canvasActions: { loadScene: false } }}
|
UIOptions={{
|
||||||
|
canvasActions: {
|
||||||
|
loadScene: false,
|
||||||
|
},
|
||||||
|
}}
|
||||||
renderTopRightUI={renderTopRightUI}
|
renderTopRightUI={renderTopRightUI}
|
||||||
onLinkOpen={onLinkOpen}
|
onLinkOpen={onLinkOpen}
|
||||||
onPointerDown={onPointerDown}
|
onPointerDown={onPointerDown}
|
||||||
|
@ -516,6 +516,7 @@ exports[`<Excalidraw/> Test UIOptions prop Test canvasActions should render menu
|
|||||||
style="margin-top: 0.5rem;"
|
style="margin-top: 0.5rem;"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
data-testid="canvas-background-label"
|
||||||
style="font-size: .75rem; margin-bottom: .5rem;"
|
style="font-size: .75rem; margin-bottom: .5rem;"
|
||||||
>
|
>
|
||||||
Canvas background
|
Canvas background
|
||||||
|
@ -199,6 +199,23 @@ describe("<Excalidraw/>", () => {
|
|||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
toggleMenu(container);
|
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(
|
||||||
|
<Excalidraw
|
||||||
|
UIOptions={{ canvasActions: { changeViewBackgroundColor: false } }}
|
||||||
|
>
|
||||||
|
<MainMenu>
|
||||||
|
<MainMenu.DefaultItems.ChangeCanvasBackground />
|
||||||
|
</MainMenu>
|
||||||
|
</Excalidraw>,
|
||||||
|
);
|
||||||
|
//open menu
|
||||||
|
toggleMenu(container);
|
||||||
|
expect(queryByTestId(container, "canvas-background-label")).toBeNull();
|
||||||
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user