From b247ebcc404a0ec7aa31e3fd3001205c318ca994 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Mon, 22 May 2023 17:26:34 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chatInput):=20fix=20chat=20i?= =?UTF-8?q?nput=20resizing=20issue=20=E2=9C=A8=20feat(chatModal):=20add=20?= =?UTF-8?q?focus=20to=20chat=20input=20when=20modal=20is=20opened=20The=20?= =?UTF-8?q?chat=20input=20was=20not=20resizing=20properly=20when=20the=20u?= =?UTF-8?q?ser=20typed=20more=20than=20one=20line=20of=20text.=20This=20wa?= =?UTF-8?q?s=20fixed=20by=20setting=20the=20height=20of=20the=20input=20to?= =?UTF-8?q?=20the=20scrollHeight=20of=20the=20input=20element.=20Additiona?= =?UTF-8?q?lly,=20the=20chat=20input=20is=20now=20focused=20when=20the=20c?= =?UTF-8?q?hat=20modal=20is=20opened,=20which=20improves=20the=20user=20ex?= =?UTF-8?q?perience.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Text area is broken #328 --- .../src/modals/chatModal/chatInput/index.tsx | 40 ++++++++++++------- src/frontend/src/modals/chatModal/index.tsx | 9 ++++- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/modals/chatModal/chatInput/index.tsx b/src/frontend/src/modals/chatModal/chatInput/index.tsx index 2fb600068..657b27f6f 100644 --- a/src/frontend/src/modals/chatModal/chatInput/index.tsx +++ b/src/frontend/src/modals/chatModal/chatInput/index.tsx @@ -1,43 +1,55 @@ import { LockClosedIcon, PaperAirplaneIcon } from "@heroicons/react/24/outline"; import { classNames } from "../../../utils"; -import { useRef } from "react"; +import { useEffect, useRef, useState } from "react"; export default function ChatInput({ lockChat, chatValue, sendMessage, setChatValue, -}: { - lockChat: boolean; - chatValue: string; - sendMessage: Function; - setChatValue: Function; + inputRef, }) { - const inputRef = useRef(null); + useEffect(() => { + if (inputRef.current) { + inputRef.current.style.height = "inherit"; // Reset the height + inputRef.current.style.height = `${inputRef.current.scrollHeight}px`; // Set it to the scrollHeight + } + }, [chatValue]); + return ( - <> +