otp auto focus
This commit is contained in:
+61
-58
@@ -1,11 +1,10 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button, FloatLabelInput } from "..";
|
import { Button } from "..";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { RouteHandler } from "../../router/routes";
|
import { RouteHandler } from "../../router/routes";
|
||||||
|
|
||||||
type FormType = {
|
type FormType = {
|
||||||
email: string;
|
[index: string] : string
|
||||||
password: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type HandleChange = {
|
type HandleChange = {
|
||||||
@@ -17,17 +16,19 @@ export default function Login() {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
|
|
||||||
let [formDetails, setFormDetails] = useState<FormType>({
|
let [values, setValues] = useState<FormType>({
|
||||||
email: "",
|
otp1: "",
|
||||||
password: "",
|
otp2: "",
|
||||||
|
otp3: "",
|
||||||
|
otp4: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleFormChange = ({
|
const handleChange = ({
|
||||||
target: { name, value },
|
target: { name, value },
|
||||||
}: {
|
}: {
|
||||||
target: HandleChange;
|
target: HandleChange;
|
||||||
}): any => {
|
}): any => {
|
||||||
setFormDetails((prev) => ({ ...prev, [name]: value }));
|
setValues((prev:FormType) => ({ ...prev, [name]: value }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
@@ -42,10 +43,20 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
const formOTP = document.querySelectorAll('input')
|
||||||
|
for (const i of formOTP) {
|
||||||
|
if (i.value === '') {
|
||||||
|
i.focus();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},[values])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`w-full overflow-y-auto bg-top bg-cover`}>
|
<div className={`w-full overflow-y-auto bg-top bg-cover`}>
|
||||||
<div className="w-full flex justify-center">
|
<div className="w-full flex justify-center">
|
||||||
<div className="w-full md:max-w-[570px]">
|
<div className="w-full xs:max-w-[350px] md:max-w-[570px]">
|
||||||
<div className="bg-white w-full rounded-2xl border-2 border-black">
|
<div className="bg-white w-full rounded-2xl border-2 border-black">
|
||||||
<div className="w-full p-5 sm:p-10 lg:p-20 flex flex-col justify-between items-center">
|
<div className="w-full p-5 sm:p-10 lg:p-20 flex flex-col justify-between items-center">
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
@@ -59,55 +70,47 @@ export default function Login() {
|
|||||||
|
|
||||||
<div className="w-full sm:w-4/5">
|
<div className="w-full sm:w-4/5">
|
||||||
{/* INPUTS */}
|
{/* INPUTS */}
|
||||||
<div className="w-full flex justify-between gap-8">
|
<div className="w-full flex justify-between gap-4">
|
||||||
<div className="relative my-2 py-2">
|
<input
|
||||||
<FloatLabelInput
|
id='otp1'
|
||||||
id="email"
|
name='otp1'
|
||||||
name="email"
|
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||||
type="email"
|
type='text'
|
||||||
// placeHolder="Email"
|
placeholder=''
|
||||||
// labelName="Email"
|
value={values.otp1}
|
||||||
value={formDetails.email}
|
onChange={handleChange}
|
||||||
inputClass=""
|
maxLength={1}
|
||||||
onChange={handleFormChange}
|
/>
|
||||||
/>
|
<input
|
||||||
</div>
|
id='otp2'
|
||||||
<div className="relative my-2 py-2">
|
name='otp2'
|
||||||
<FloatLabelInput
|
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||||
id="password"
|
type='text'
|
||||||
name="password"
|
placeholder=''
|
||||||
type="password"
|
value={values.otp2}
|
||||||
// placeHolder="Password"
|
onChange={handleChange}
|
||||||
// labelName="Password"
|
maxLength={1}
|
||||||
value={formDetails.password}
|
/>
|
||||||
inputClass=""
|
<input
|
||||||
onChange={handleFormChange}
|
id='otp3'
|
||||||
/>
|
name='otp3'
|
||||||
</div>
|
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||||
<div className="relative my-2 py-2">
|
type='text'
|
||||||
<FloatLabelInput
|
placeholder=''
|
||||||
id="passwor"
|
value={values.otp3}
|
||||||
name="passwor"
|
onChange={handleChange}
|
||||||
type="password"
|
maxLength={1}
|
||||||
// placeHolder="Password"
|
/>
|
||||||
// labelName="Password"
|
<input
|
||||||
value={formDetails.password}
|
id='otp4'
|
||||||
inputClass=""
|
name='otp4'
|
||||||
onChange={handleFormChange}
|
className={`custom-otp text-center w-12 h-12 outline-none border-b-2 border-b-[#5A2C82] placeholder:text-transparent transition-all duration-500`}
|
||||||
/>
|
type='text'
|
||||||
</div>
|
placeholder=''
|
||||||
<div className="relative my-2 py-2">
|
value={values.otp4}
|
||||||
<FloatLabelInput
|
onChange={handleChange}
|
||||||
id="passw"
|
maxLength={1}
|
||||||
name="passw"
|
/>
|
||||||
type="password"
|
|
||||||
// placeHolder="Password"
|
|
||||||
// labelName="Password"
|
|
||||||
value={formDetails.password}
|
|
||||||
inputClass=""
|
|
||||||
onChange={handleFormChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-10 w-full">
|
<div className="mt-10 w-full">
|
||||||
|
|||||||
+5
-1
@@ -5,7 +5,11 @@ export default {
|
|||||||
"./src/**/*.{js,ts,jsx,tsx}",
|
"./src/**/*.{js,ts,jsx,tsx}",
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {
|
||||||
|
screens:{
|
||||||
|
xs: "400px",
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user