diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index f0c2d1d63c5..98b6c62e664 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -108,6 +108,8 @@ const Login = (props: LoginProps) => { const [otpError, setOtpError] = useState(""); const [otpValidationError, setOtpValidationError] = useState(""); const [resendOtpCountdown, setResendOtpCountdown] = useState(0); + const activeMode = + !disablePatientLogin && mode === "patient" ? "patient" : "staff"; // Timer Function for resend OTP useEffect(() => { @@ -127,6 +129,16 @@ const Login = (props: LoginProps) => { localStorage.setItem(LocalStorageKeys.loginPreference, mode); }, [mode]); + // Autofocuses when switching tabs + useEffect(() => { + const frame = requestAnimationFrame(() => { + document + .getElementById(activeMode === "staff" ? "username" : "phone") + ?.focus(); + }); + return () => cancelAnimationFrame(frame); + }, [activeMode]); + // Send OTP Mutation const { mutate: sendOtp, isPending: sendOtpPending } = useMutation({ mutationFn: mutate(otpApi.send),