import "./TextInput.scss"; import React, { Component } from "react"; import { selectNode, removeSelection } from "../utils"; type Props = { value: string; onChange: (value: string) => void; label: string; isNameEditable: boolean; }; export class ProjectName extends Component { private handleFocus = (event: React.FocusEvent) => { selectNode(event.currentTarget); }; private handleBlur = (event: React.FocusEvent) => { const value = event.currentTarget.innerText.trim(); if (value !== this.props.value) { this.props.onChange(value); } removeSelection(); }; private handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault(); if (event.nativeEvent.isComposing || event.keyCode === 229) { return; } event.currentTarget.blur(); } }; private makeEditable = (editable: HTMLSpanElement | null) => { if (!editable) { return; } try { editable.contentEditable = "plaintext-only"; } catch { editable.contentEditable = "true"; } }; public render() { return this.props.isNameEditable ? ( {this.props.value} ) : ( {this.props.value} ); } }