From 4fb637e153cbad0b215cb63d5a446deaf8275701 Mon Sep 17 00:00:00 2001 From: lizerk Date: Fri, 3 Apr 2026 12:21:50 +0300 Subject: [PATCH] Improve message composer behavior --- .../components/messages/MessageComposer.tsx | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/messages/MessageComposer.tsx b/frontend/src/components/messages/MessageComposer.tsx index 8db46b18..274d11f3 100644 --- a/frontend/src/components/messages/MessageComposer.tsx +++ b/frontend/src/components/messages/MessageComposer.tsx @@ -1,8 +1,12 @@ "use client"; +import { useLayoutEffect, useState } from "react"; import type React from "react"; import { Paperclip, Send, Smile, X } from "lucide-react"; +const MIN_COMPOSER_HEIGHT = 42; +const MAX_COMPOSER_HEIGHT = 128; + type ReplyTarget = { id: number; author: string; @@ -58,6 +62,22 @@ export default function MessageComposer({ onCancelEdit, onCancelReply, }: MessageComposerProps) { + const [isExpanded, setIsExpanded] = useState(false); + const canSend = editingMessageId ? messageText.trim().length > 0 : messageText.trim().length > 0 || attachedFiles.length > 0; + + useLayoutEffect(() => { + const input = messageInputRef.current; + if (!input) return; + + input.style.height = "0px"; + const nextHeight = Math.min(input.scrollHeight, MAX_COMPOSER_HEIGHT); + const resolvedHeight = Math.max(nextHeight, MIN_COMPOSER_HEIGHT); + + input.style.height = `${resolvedHeight}px`; + input.style.overflowY = input.scrollHeight > MAX_COMPOSER_HEIGHT ? "auto" : "hidden"; + setIsExpanded(resolvedHeight > MIN_COMPOSER_HEIGHT + 2); + }, [messageText, messageInputRef]); + return ( <> {editingMessageId ? ( @@ -124,22 +144,34 @@ export default function MessageComposer({ className="hidden" onChange={onFilesChange} /> - + -
@@ -177,16 +209,20 @@ export default function MessageComposer({ }} rows={1} placeholder={editingMessageId ? "Редактируйте сообщение..." : "Введите сообщение..."} - className="min-h-[42px] max-h-32 w-full resize-none rounded-[1.35rem] border border-gray-200 bg-gray-50 px-4 py-2.5 pr-12 text-sm text-gray-800 outline-none transition placeholder:text-gray-400 focus:border-sky-500 focus:bg-white focus:outline-none focus:ring-2 focus:ring-sky-100" + aria-label={editingMessageId ? "Редактирование сообщения" : "Поле ввода сообщения"} + className={`w-full resize-none bg-transparent py-2.5 pl-11 pr-12 text-sm leading-5 text-gray-800 outline-none placeholder:text-gray-400 ${ + isExpanded ? "rounded-[1.5rem]" : "rounded-full" + }`} />