diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index 043747a06..d49faf8c6 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -23,7 +23,7 @@ export const actionChangeProjectName = register({ label={t("labels.fileTitle")} value={appState.name || "Unnamed"} onChange={(name: string) => updateData(name)} - isNameEditable={typeof appProps.name !== "undefined"} + isNameEditable={typeof appProps.name === "undefined"} /> ), }); diff --git a/src/components/App.tsx b/src/components/App.tsx index c811245a4..ebf4d1e0e 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -905,7 +905,7 @@ class App extends React.Component { }); } - if (prevProps.name !== this.props.name && this.props.name) { + if (this.props.name && prevProps.name !== this.props.name) { this.setState({ name: this.props.name, }); diff --git a/src/components/ExportDialog.tsx b/src/components/ExportDialog.tsx index cc4219a51..bad31a910 100644 --- a/src/components/ExportDialog.tsx +++ b/src/components/ExportDialog.tsx @@ -257,6 +257,7 @@ export const ExportDialog = ({ onClick={() => { setModalIsShown(true); }} + data-testid="export-button" icon={exportFile} type="button" aria-label={t("buttons.export")} diff --git a/src/components/ProjectName.tsx b/src/components/ProjectName.tsx index 067011f21..6c2ab0d87 100644 --- a/src/components/ProjectName.tsx +++ b/src/components/ProjectName.tsx @@ -45,10 +45,6 @@ export class ProjectName extends Component { public render() { return this.props.isNameEditable ? ( - - {this.props.value} - - ) : ( { > {this.props.value} + ) : ( + + {this.props.value} + ); } } diff --git a/src/components/ToolButton.tsx b/src/components/ToolButton.tsx index af90dde63..68db6dcfa 100644 --- a/src/components/ToolButton.tsx +++ b/src/components/ToolButton.tsx @@ -58,6 +58,7 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => { "ToolIcon--selected": props.selected, }, )} + data-testid={props["data-testid"]} hidden={props.hidden} title={props.title} aria-label={props["aria-label"]} diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md index edb157512..fdcd1a815 100644 --- a/src/packages/excalidraw/CHANGELOG.md +++ b/src/packages/excalidraw/CHANGELOG.md @@ -18,6 +18,7 @@ Please add the latest change on the top under the correct section. ### Features +- Add `name` prop which allows changing the export name. When this prop is passed, the name is fully controlled by host and will become unediable in the export modal [#3273](https://github.com/excalidraw/excalidraw/pull/3273). - Export API to export the drawing to canvas, svg and blob [#3258](https://github.com/excalidraw/excalidraw/pull/3258). For more info you can check the [readme](https://github.com/excalidraw/excalidraw/tree/master/src/packages/excalidraw/README.md#user-content-export-utils) - Add a `theme` prop to indicate Excalidraw's theme. [#3228](https://github.com/excalidraw/excalidraw/pull/3228). When this prop is passed, the theme is fully controlled by host app. - Support `libraryReturnUrl` prop to indicate what URL to install libraries to [#3227](https://github.com/excalidraw/excalidraw/pull/3227). diff --git a/src/tests/excalidrawPackage.test.tsx b/src/tests/excalidrawPackage.test.tsx index 9351a7f27..912d3887b 100644 --- a/src/tests/excalidrawPackage.test.tsx +++ b/src/tests/excalidrawPackage.test.tsx @@ -3,6 +3,7 @@ import { fireEvent, GlobalTestState, render } from "./test-utils"; import Excalidraw from "../packages/excalidraw/index"; import { queryByText, queryByTestId } from "@testing-library/react"; import { GRID_SIZE } from "../constants"; +import { t } from "../i18n"; const { h } = window; @@ -104,4 +105,27 @@ describe("", () => { expect(queryByTestId(container, "toggle-dark-mode")).toBe(null); }); }); + + describe("Test name prop", () => { + it('should allow editing the export name when the name prop is "undefined"', async () => { + const { container } = await render(); + expect(h.state.name).toContain(`${t("labels.untitled")}`); + + fireEvent.click(queryByTestId(container, "export-button")!); + + const name = document.querySelector(".ExportDialog__name span"); + + expect(name?.hasAttribute("data-type")).toBe(true); + }); + + it('should not allow editing the export name when the name prop is not "undefined"', async () => { + const { container } = await render(); + + fireEvent.click(queryByTestId(container, "export-button")!); + + const name = document.querySelector(".ExportDialog__name span"); + + expect(name?.hasAttribute("data-type")).toBe(false); + }); + }); });