Skip to content

Commit

Permalink
fix: handle resize on reopening chat
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed May 20, 2024
1 parent 5bbc4bf commit 9bce904
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
}
};

const updateInputHeight = () => {
if (inputRef.current) {
inputRef.current.style.height = `${Math.max(32, Math.min(inputRef.current.scrollHeight, 24 * 4))}px`;
}
};

const sendMessage = useCallback(async () => {
const message = inputRef?.current?.value;
if (!message || !message.trim().length) {
Expand Down Expand Up @@ -139,6 +145,7 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
const messageElement = inputRef.current;
if (messageElement) {
messageElement.value = draftMessage;
updateInputHeight();
}
}, [draftMessage]);

Expand Down Expand Up @@ -245,10 +252,7 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
}}
autoComplete="off"
aria-autocomplete="none"
onChange={e => {
const element = e.target;
element.style.height = `${Math.min(element.scrollHeight, 24 * 4)}px`;
}}
onChange={updateInputHeight}
onBlur={resetInputHeight}
onPaste={e => e.stopPropagation()}
onCut={e => e.stopPropagation()}
Expand Down

0 comments on commit 9bce904

Please sign in to comment.