diff --git a/client/src/components/chat/MessageForm.tsx b/client/src/components/chat/MessageForm.tsx index c53227a..5961eaf 100644 --- a/client/src/components/chat/MessageForm.tsx +++ b/client/src/components/chat/MessageForm.tsx @@ -1,12 +1,15 @@ import { sendMessage } from '../../socket/socket.tsx'; import { useForm, SubmitHandler } from 'react-hook-form'; + type Input = { message: string; }; + type MessaFormProps = { contact: string; }; -function messageForm({ contact }: MessaFormProps) { + +function MessageForm({ contact }: MessaFormProps) { const { register, handleSubmit, @@ -17,46 +20,59 @@ function messageForm({ contact }: MessaFormProps) { // Sending message const submitMessage: SubmitHandler = (data) => { console.log(contact); - // block sending empty message + + // Block sending empty message if (!data.message) { return; } - // for (let i = 0; i <= 200; i++) { - // let ii = i.toString(); - // sendMessage(ii, contact); - // } - sendMessage(data.message, contact); + sendMessage(data.message, contact); reset({ message: '' }); }; + const adjustSize = (event) => { + const textarea = event.target; + + // Adjust height + textarea.style.height = 'auto'; + const maxHeight = 500; + + if (textarea.scrollHeight > maxHeight) { + textarea.style.height = `${maxHeight}px`; + textarea.style.overflowY = 'auto'; + } else { + textarea.style.height = `${textarea.scrollHeight}px`; + textarea.style.overflowY = 'hidden'; + } + }; + return ( - <> -
-
- - {errors?.message?.type === 'maxLength' && ( -

Maximum length of the message is 500

- )} - -
-
- +
+
+