import React, { ChangeEvent, KeyboardEvent } from "react"; import LabelWithHelpIcon from "./LabelWithHelpIcon"; type Props = { name?: string; label?: string; placeholder?: string; value?: string; autofocus?: boolean; onChange: (value: string, name?: string) => void; helpText?: string; disabled?: boolean; onSubmit?: () => void; onCancel?: () => void; }; class Textarea extends React.Component { field: HTMLTextAreaElement | null | undefined; componentDidMount() { if (this.props.autofocus && this.field) { this.field.focus(); } } handleInput = (event: ChangeEvent) => { this.props.onChange(event.target.value, this.props.name); }; onKeyPress = (event: KeyboardEvent) => { const { onSubmit } = this.props; if (onSubmit && event.key === "Enter" && event.ctrlKey) { onSubmit(); } }; onKeyDown = (event: KeyboardEvent) => { const { onCancel } = this.props; if (onCancel && event.key === "Escape") { onCancel(); } }; render() { const { placeholder, value, label, helpText, disabled } = this.props; return (