From 01809372620f7ca3e24b6c88d1eb2c57cd7cf263 Mon Sep 17 00:00:00 2001 From: 0xSage Date: Fri, 13 Oct 2023 15:32:43 +0800 Subject: [PATCH] fix: textarea should resize after sending --- .../_components/BasicPromptInput/index.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/web/app/_components/BasicPromptInput/index.tsx b/web/app/_components/BasicPromptInput/index.tsx index 7490aa993..6696697b7 100644 --- a/web/app/_components/BasicPromptInput/index.tsx +++ b/web/app/_components/BasicPromptInput/index.tsx @@ -18,6 +18,8 @@ const BasicPromptInput: React.FC = () => { const { initModel } = useInitModel(); + const textareaRef = useRef(null); + const handleKeyDown = async ( event: React.KeyboardEvent ) => { @@ -40,12 +42,19 @@ const BasicPromptInput: React.FC = () => { } }; + useEffect(() => { + adjustTextareaHeight(); + }, [currentPrompt]); + + const handleMessageChange = (event: ChangeEvent) => { + setCurrentPrompt(event.target.value); + }; + // Auto adjust textarea height based on content - const textareaRef = useRef(null); const MAX_ROWS = 10; const adjustTextareaHeight = () => { if (textareaRef.current) { - textareaRef.current.style.height = "auto"; + textareaRef.current.style.height = "auto"; // 1 row const scrollHeight = textareaRef.current.scrollHeight; const maxScrollHeight = parseInt(window.getComputedStyle(textareaRef.current).lineHeight, 10) * @@ -57,15 +66,6 @@ const BasicPromptInput: React.FC = () => { } }; - useEffect(() => { - adjustTextareaHeight(); - }, []); - - const handleMessageChange = (event: ChangeEvent) => { - setCurrentPrompt(event.target.value); - adjustTextareaHeight(); - }; - return (