From 8bbb3c14f8f7750cae7172a3bae6f304827fd159 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Wed, 7 Aug 2024 22:14:49 +0530 Subject: [PATCH] refactor: Improve textarea focus behavior in PlaygroundForm component --- src/components/Option/Playground/PlaygroundForm.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index 8d248f8..8aee6e3 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -39,15 +39,26 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { selectedKnowledge } = useMessageOption() + const isMobile = () => { + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( + navigator.userAgent + ) + } + const textAreaFocus = () => { if (textareaRef.current) { if ( textareaRef.current.selectionStart === textareaRef.current.selectionEnd ) { - textareaRef.current.focus() + if (!isMobile()) { + textareaRef.current.focus() + } else { + textareaRef.current.blur() + } } } } + const form = useForm({ initialValues: { message: "",