From 8f7a85969157c600efddbb315573c698274517f8 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Sat, 4 Mar 2023 21:30:57 +0800 Subject: [PATCH] reset sticky textarea height after save/submit --- .../Chat/ChatContent/Message/MessageContent.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/MessageContent.tsx b/src/components/Chat/ChatContent/Message/MessageContent.tsx index d82ebb4..5ad4487 100644 --- a/src/components/Chat/ChatContent/Message/MessageContent.tsx +++ b/src/components/Chat/ChatContent/Message/MessageContent.tsx @@ -291,6 +291,10 @@ const EditView = ({ const [isModalOpen, setIsModalOpen] = useState(false); const textareaRef = React.createRef(); + const resetTextAreaHeight = () => { + if (textareaRef.current) textareaRef.current.style.height = 'auto'; + }; + const handleInput = (e: React.ChangeEvent) => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; @@ -301,8 +305,10 @@ const EditView = ({ const handleKeyDown = (e: React.KeyboardEvent) => { if ((e.ctrlKey || e.shiftKey) && e.key === 'Enter') { e.preventDefault(); - if (sticky) handleSaveAndSubmit(); - else handleSave(); + if (sticky) { + handleSaveAndSubmit(); + resetTextAreaHeight(); + } else handleSave(); } }; @@ -314,6 +320,7 @@ const EditView = ({ if (sticky) { updatedMessages.push({ role: inputRole, content: _content }); _setContent(''); + resetTextAreaHeight(); } else { updatedMessages[messageIndex].content = _content; setIsEdit(false); @@ -331,6 +338,7 @@ const EditView = ({ updatedMessages.push({ role: inputRole, content: _content }); _setContent(''); setMessages(updatedMessages); + resetTextAreaHeight(); } else { updatedMessages[messageIndex].content = _content; const _updatedMessages = updatedMessages.slice(0, messageIndex + 1);