reset sticky textarea height after save/submit

This commit is contained in:
Jing Hua 2023-03-04 21:30:57 +08:00
parent e8c0ddaa96
commit 8f7a859691

View file

@ -291,6 +291,10 @@ const EditView = ({
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const textareaRef = React.createRef<HTMLTextAreaElement>(); const textareaRef = React.createRef<HTMLTextAreaElement>();
const resetTextAreaHeight = () => {
if (textareaRef.current) textareaRef.current.style.height = 'auto';
};
const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => { const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
if (textareaRef.current) { if (textareaRef.current) {
textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = 'auto';
@ -301,8 +305,10 @@ const EditView = ({
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if ((e.ctrlKey || e.shiftKey) && e.key === 'Enter') { if ((e.ctrlKey || e.shiftKey) && e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
if (sticky) handleSaveAndSubmit(); if (sticky) {
else handleSave(); handleSaveAndSubmit();
resetTextAreaHeight();
} else handleSave();
} }
}; };
@ -314,6 +320,7 @@ const EditView = ({
if (sticky) { if (sticky) {
updatedMessages.push({ role: inputRole, content: _content }); updatedMessages.push({ role: inputRole, content: _content });
_setContent(''); _setContent('');
resetTextAreaHeight();
} else { } else {
updatedMessages[messageIndex].content = _content; updatedMessages[messageIndex].content = _content;
setIsEdit(false); setIsEdit(false);
@ -331,6 +338,7 @@ const EditView = ({
updatedMessages.push({ role: inputRole, content: _content }); updatedMessages.push({ role: inputRole, content: _content });
_setContent(''); _setContent('');
setMessages(updatedMessages); setMessages(updatedMessages);
resetTextAreaHeight();
} else { } else {
updatedMessages[messageIndex].content = _content; updatedMessages[messageIndex].content = _content;
const _updatedMessages = updatedMessages.slice(0, messageIndex + 1); const _updatedMessages = updatedMessages.slice(0, messageIndex + 1);