Skip to content

Commit

Permalink
Fix for event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
CoenWarmer committed Aug 8, 2023
1 parent 3063d8a commit 9915344
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export function ChatPromptEditor({ disabled, loading, onSubmit }: ChatPromptEdit
setFunctionPayload('');
};

const handleResizeTextArea = (textarea: HTMLTextAreaElement | null) => {
if (textarea) {
textarea.style.height = 'auto';
textarea.style.height = textarea?.scrollHeight + 'px';
const handleResizeTextArea = () => {
if (textAreaRef.current) {
textAreaRef.current.style.height = 'auto';
textAreaRef.current.style.height = textAreaRef.current?.scrollHeight + 'px';
}
};

Expand All @@ -73,7 +73,7 @@ export function ChatPromptEditor({ disabled, loading, onSubmit }: ChatPromptEdit

setPrompt('');
setFunctionPayload(undefined);
handleResizeTextArea(textAreaRef.current);
handleResizeTextArea();

try {
if (selectedFunction) {
Expand Down Expand Up @@ -119,11 +119,11 @@ export function ChatPromptEditor({ disabled, loading, onSubmit }: ChatPromptEdit

if (textarea) {
textarea.focus();
textarea.addEventListener('input', () => handleResizeTextArea(textarea), false);
textarea.addEventListener('input', handleResizeTextArea, false);
}

return () => {
textarea?.removeEventListener('input', () => handleResizeTextArea(textarea), false);
textarea?.removeEventListener('input', handleResizeTextArea, false);
};
});

Expand Down

0 comments on commit 9915344

Please sign in to comment.