refactor: Improve textarea focus behavior in PlaygroundForm component

This commit is contained in:
n4ze3m 2024-08-07 22:14:49 +05:30
parent f6d7020fe0
commit 8bbb3c14f8

View File

@ -39,15 +39,26 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
selectedKnowledge selectedKnowledge
} = useMessageOption() } = useMessageOption()
const isMobile = () => {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
}
const textAreaFocus = () => { const textAreaFocus = () => {
if (textareaRef.current) { if (textareaRef.current) {
if ( if (
textareaRef.current.selectionStart === textareaRef.current.selectionEnd textareaRef.current.selectionStart === textareaRef.current.selectionEnd
) { ) {
if (!isMobile()) {
textareaRef.current.focus() textareaRef.current.focus()
} else {
textareaRef.current.blur()
} }
} }
} }
}
const form = useForm({ const form = useForm({
initialValues: { initialValues: {
message: "", message: "",