import {observer} from 'mobx-react'; import * as React from 'react'; import {ErrorMessage} from '../ErrorMessage'; import {Label} from '../Label'; import styles from './TextAreaField.scss'; import classNames from 'classnames'; interface TextAreaFieldProps { text: string; onChange: (text: string) => void; label?: string; placeholder?: string; disabled?: boolean; fitToContentHeight?: boolean; error?: string; onKeyDown?: (e: React.KeyboardEvent) => void; onFocus?: () => void; onBlur?: () => void; inputRef?: (e: HTMLTextAreaElement) => void; className?: string; inputClassName?: string; } @observer export class TextAreaField extends React.Component { private textareaReference: HTMLTextAreaElement; componentDidMount() { this.fitHeightToContent(); } componentDidUpdate() { this.fitHeightToContent(); } private fitHeightToContent() { if (this.props.fitToContentHeight) { this.textareaReference.style.height = 'auto'; this.textareaReference.style.height = (this.textareaReference.scrollHeight) + 'px'; } } private handleReference = (reference: HTMLTextAreaElement) => { this.textareaReference = reference; this.props.inputRef && this.props.inputRef(reference); } private handleChange = (e: React.ChangeEvent) => { this.props.onChange(e.target.value); } public render() { const {text, label, placeholder, disabled, error, onKeyDown, onFocus, onBlur, className, inputClassName} = this.props; return (
{label &&