import "./TextInput.scss"; import React, { Component } from "react"; import { focusNearestParent } from "../utils"; import "./ProjectName.scss"; type Props = { value: string; onChange: (value: string) => void; label: string; isNameEditable: boolean; }; type State = { fileName: string; }; export class ProjectName extends Component { state = { fileName: this.props.value, }; private handleBlur = (event: any) => { focusNearestParent(event.target); const value = event.target.value; if (value !== this.props.value) { this.props.onChange(value); } }; private handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault(); if (event.nativeEvent.isComposing || event.keyCode === 229) { return; } event.currentTarget.blur(); } }; public render() { return (
{this.props.isNameEditable ? ( this.setState({ fileName: event.target.value }) } /> ) : ( {this.props.value} )}
); } }