mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-26 00:23:59 +01:00
reset sticky textarea height after save/submit
This commit is contained in:
parent
e8c0ddaa96
commit
8f7a859691
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue