diff --git a/src/components/EditableText.tsx b/src/components/EditableText.tsx index 7fc825896..e9ffecd1d 100644 --- a/src/components/EditableText.tsx +++ b/src/components/EditableText.tsx @@ -1,51 +1,38 @@ -import React, { createRef, Fragment, Component } from "react"; +import React, { Fragment, Component } from "react"; type InputState = { - initialValue: string; value: string; edit: boolean; }; type Props = { value: string; - updateName: (name: string) => void; + onChange: (value: string) => void; }; -export default class EditableInput extends Component { +export default class EditableText extends Component { constructor(props: Props) { super(props); - const { value } = props; this.state = { - initialValue: value, - value, + value: props.value, edit: false }; } - private inputRef = createRef(); - private handleEdit(e: React.ChangeEvent) { this.setState({ value: e.target.value }); } private handleBlur() { - const { value, initialValue } = this.state; + const { value } = this.state; if (!value) { - this.setState({ value: initialValue, edit: false }); + this.setState({ value: this.props.value, edit: false }); return; } - this.props.updateName(value); - this.setState({ edit: false, initialValue: value }); - } - - private focusInput() { - const input = this.inputRef.current; - if (input) { - input.focus(); - } - this.setState({ edit: true }); + this.props.onChange(value); + this.setState({ edit: false }); } public render() { @@ -61,10 +48,13 @@ export default class EditableInput extends Component { value={value} onChange={e => this.handleEdit(e)} onBlur={() => this.handleBlur()} - ref={this.inputRef} + autoFocus /> ) : ( - this.focusInput()} className="project-name"> + this.setState({ edit: true })} + className="project-name" + > {value} )} diff --git a/src/index.tsx b/src/index.tsx index 49edf76e1..d1299765e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -626,7 +626,7 @@ function exportAsPNG({ } ); - saveFile(name, tempCanvas.toDataURL("image/png")); + saveFile(`${name}.png`, tempCanvas.toDataURL("image/png")); // clean up the DOM if (tempCanvas !== canvas) tempCanvas.remove(); @@ -992,6 +992,7 @@ class App extends React.Component<{}, AppState> { this.setState(savedState); } + // set default name if (!(savedState && savedState.name)) { const name = `excalidraw-${getDateTime()}`; this.setState({ name }); @@ -1147,8 +1148,6 @@ class App extends React.Component<{}, AppState> { const canvasWidth = window.innerWidth - CANVAS_WINDOW_OFFSET_LEFT; const canvasHeight = window.innerHeight - CANVAS_WINDOW_OFFSET_TOP; - const { name } = this.state; - return (
{ >

Project name

- {name && ( + {this.state.name && ( this.updateProjectName(name)} + value={this.state.name} + onChange={(name: string) => this.updateProjectName(name)} /> )} -

Shapes

{SHAPES.map(({ value, icon }) => (