From 505ff2f7b590ec7b0e3a00f9b6356bc02e6bf397 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 2 Jul 2026 23:14:44 +0330 Subject: [PATCH] add focus --- src/pages/auth/components/LoginStep1.tsx | 7 ++-- src/pages/auth/components/LoginStep2.tsx | 43 +++++++++++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/pages/auth/components/LoginStep1.tsx b/src/pages/auth/components/LoginStep1.tsx index 04a6661..1904586 100644 --- a/src/pages/auth/components/LoginStep1.tsx +++ b/src/pages/auth/components/LoginStep1.tsx @@ -39,7 +39,7 @@ const LoginStep1: FC = () => { }) return ( -
+

خوش آمدید @@ -56,6 +56,7 @@ const LoginStep1: FC = () => { type='tel' autoComplete='tel' inputMode='tel' + autoFocus className='dltr text-left' name='phone_email' onChange={formik.handleChange} @@ -75,10 +76,10 @@ const LoginStep1: FC = () => {

+
) } diff --git a/src/pages/auth/components/LoginStep2.tsx b/src/pages/auth/components/LoginStep2.tsx index 4d2b26f..65b6b2e 100644 --- a/src/pages/auth/components/LoginStep2.tsx +++ b/src/pages/auth/components/LoginStep2.tsx @@ -1,4 +1,4 @@ -import { type FC, useEffect } from 'react' +import { type FC, useEffect, useRef } from 'react' import { type OtpVerifyType } from '../types/AuthTypes' import { useFormik } from 'formik' import * as Yup from 'yup' @@ -19,6 +19,7 @@ const LoginStep2: FC = () => { const { value, reset } = useCountDown(2, true) const otpVerify = useOtpVerify() const loginWithOtp = useLoginWithOtp() + const firstOtpInputRef = useRef(null) const formik = useFormik({ initialValues: { @@ -48,6 +49,14 @@ const LoginStep2: FC = () => { }, }) + useEffect(() => { + const frameId = requestAnimationFrame(() => { + firstOtpInputRef.current?.focus() + }) + + return () => cancelAnimationFrame(frameId) + }, []) + useEffect(() => { // بررسی پشتیبانی از Web OTP API if (!("OTPCredential" in window)) return; @@ -93,7 +102,7 @@ const LoginStep2: FC = () => { return ( -
+

کد تایید را وارد کنید @@ -123,14 +132,24 @@ const LoginStep2: FC = () => { numInputs={5} inputType='tel' onChange={(otp: string) => formik.setFieldValue('otp', otp)} - renderInput={(props) => - - } + renderInput={(props, index) => { + const { ref, ...inputProps } = props + + return ( + { + ref(element) + if (index === 0) { + firstOtpInputRef.current = element + } + }} + type='tel' + autoComplete="one-time-otp" + inputMode="numeric" + className='w-full h-[50px] min-w-[50px] flex-1 mx-2 bg-white border border-border rounded-[10px]' /> + ) + }} />

@@ -163,7 +182,7 @@ const LoginStep2: FC = () => {
*/} -
+ ) }