From fd626b14b278c44ce125f5636c5b0b8b952f6c11 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Wed, 20 Mar 2024 14:53:12 -0700 Subject: [PATCH] [FEAT] Improve UX of PromptInput (#939) improve UX of PromptInput + cleanup props --- .../ChatContainer/PromptInput/index.jsx | 31 +++++++++++++------ .../WorkspaceChat/ChatContainer/index.jsx | 1 - 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx index 52e8701233..d424c906f4 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/index.jsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; import SlashCommandsButton, { SlashCommands, useSlashCommands, @@ -7,9 +7,7 @@ import { isMobile } from "react-device-detect"; import debounce from "lodash.debounce"; import { PaperPlaneRight } from "@phosphor-icons/react"; import StopGenerationButton from "./StopGenerationButton"; - export default function PromptInput({ - workspace, message, submit, onChange, @@ -19,13 +17,27 @@ export default function PromptInput({ }) { const { showSlashCommand, setShowSlashCommand } = useSlashCommands(); const formRef = useRef(null); + const textareaRef = useRef(null); const [_, setFocused] = useState(false); + useEffect(() => { + if (!inputDisabled && textareaRef.current) { + textareaRef.current.focus(); + } + resetTextAreaHeight(); + }, [inputDisabled]); + const handleSubmit = (e) => { setFocused(false); submit(e); }; + const resetTextAreaHeight = () => { + if (textareaRef.current) { + textareaRef.current.style.height = "auto"; + } + }; + const checkForSlash = (e) => { const input = e.target.value; if (input === "/") setShowSlashCommand(true); @@ -44,14 +56,12 @@ export default function PromptInput({ const adjustTextArea = (event) => { if (isMobile) return false; const element = event.target; - element.style.height = "1px"; - element.style.height = - event.target.value.length !== 0 - ? 25 + element.scrollHeight + "px" - : "1px"; + element.style.height = "auto"; + element.style.height = `${element.scrollHeight}px`; }; const watchForSlash = debounce(checkForSlash, 300); + return (