From 9915344b460cb24b5641b0922c018b6773a10079 Mon Sep 17 00:00:00 2001 From: Coen Warmer Date: Tue, 8 Aug 2023 12:03:58 +0200 Subject: [PATCH] Fix for event handler --- .../public/components/chat/chat_prompt_editor.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_prompt_editor.tsx b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_prompt_editor.tsx index b21f2d0944efc..8937afabf663e 100644 --- a/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_prompt_editor.tsx +++ b/x-pack/plugins/observability_ai_assistant/public/components/chat/chat_prompt_editor.tsx @@ -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'; } }; @@ -73,7 +73,7 @@ export function ChatPromptEditor({ disabled, loading, onSubmit }: ChatPromptEdit setPrompt(''); setFunctionPayload(undefined); - handleResizeTextArea(textAreaRef.current); + handleResizeTextArea(); try { if (selectedFunction) { @@ -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); }; });