diff --git a/web/chat/chat-input-text-area.react.js b/web/chat/chat-input-text-area.react.js new file mode 100644 --- /dev/null +++ b/web/chat/chat-input-text-area.react.js @@ -0,0 +1,111 @@ +// @flow + +import invariant from 'invariant'; +import * as React from 'react'; + +import css from './chat-input-bar.css'; + +type BaseProps = { + +send?: () => mixed, + +escape?: () => void, + +focus: boolean, + +currentText: string, +}; +type Props = { + ...BaseProps, +}; + +class ChatInputTextArea extends React.PureComponent { + textarea: ?HTMLTextAreaElement; + + componentDidMount() { + this.updateHeight(); + this.focusAndUpdateText(); + } + + componentDidUpdate(prevProps: Props) { + const { currentText } = this.props; + const { currentText: prevText } = prevProps; + if (currentText !== prevText) { + this.updateHeight(); + } + } + + updateHeight() { + const textarea = this.textarea; + if (textarea) { + textarea.style.height = 'auto'; + const newHeight = Math.min(textarea.scrollHeight, 150); + textarea.style.height = `${newHeight}px`; + } + } + + render() { + return ( +
+