diff --git a/frontend/src/components/TextArea.tsx b/frontend/src/components/TextArea.tsx new file mode 100644 index 00000000..b650423f --- /dev/null +++ b/frontend/src/components/TextArea.tsx @@ -0,0 +1,71 @@ +import React, { useEffect, useRef } from 'react'; + +type Props = { + value: string | string[] | number; + isAutoFocused: boolean; + id?: string; + maxLength?: number; + name?: string; + placeholder?: string; + className?: string; + children?: React.ReactElement; + onChange: (e: React.ChangeEvent) => void; + onPaste?: (e: React.ClipboardEvent) => void; + onKeyDown?: (e: React.KeyboardEvent) => void; +}; + +const TextArea = ({ + value, + isAutoFocused, + id, + maxLength, + name, + placeholder, + className, + children, + onChange, + onPaste, + onKeyDown, +}: Props) => { + const textAreaRef = useRef(null); + + useEffect(() => { + const autoResizeTextArea = () => { + if (textAreaRef.current) { + textAreaRef.current.style.height = 'auto'; + + const maxHeight = 96; + const currentContentHeight = textAreaRef.current.scrollHeight; + + const newHeight = Math.min(maxHeight, currentContentHeight); + + textAreaRef.current.style.height = `${newHeight}px`; + } + }; + + autoResizeTextArea(); + }, [value]); + + return ( + + ); +}; + +export default TextArea; diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 96f1eecb..58af6d09 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -20,7 +20,7 @@ import { sendFeedback } from './conversationApi'; import { useTranslation } from 'react-i18next'; import ArrowDown from './../assets/arrow-down.svg'; import RetryIcon from '../components/RetryIcon'; -import TextInput from '../components/inputs/TextInput'; +import TextArea from '../components/TextArea'; export default function Conversation() { const queries = useSelector(selectQueries); const status = useSelector(selectStatus); @@ -232,9 +232,9 @@ export default function Conversation() {
- setPrompt(e.target.value)} placeholder={t('inputPlaceholder')} onPaste={handlePaste} @@ -244,7 +244,7 @@ export default function Conversation() { handleQuestionSubmission(); } }} - > + >{' '} {status === 'loading' ? (