dhre-ui-kit 0.0.259 → 0.0.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +22 -14
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +22 -14
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -3995,7 +3995,8 @@ const OTPInput = React.forwardRef(
|
|
|
3995
3995
|
}
|
|
3996
3996
|
return () => clearInterval(timer);
|
|
3997
3997
|
}, [timeLeft, isResendOtpEnable]);
|
|
3998
|
-
const
|
|
3998
|
+
const refs = useRef([]);
|
|
3999
|
+
refs.current = Array(length).fill(0).map((_, index) => refs.current[index] || null);
|
|
3999
4000
|
useEffect(() => {
|
|
4000
4001
|
enableResendOtp();
|
|
4001
4002
|
}, []);
|
|
@@ -4014,7 +4015,11 @@ const OTPInput = React.forwardRef(
|
|
|
4014
4015
|
}
|
|
4015
4016
|
};
|
|
4016
4017
|
const disableResendButton = () => {
|
|
4017
|
-
|
|
4018
|
+
if (disabled === true && resendOTPCount >= maxResendCount) {
|
|
4019
|
+
return true;
|
|
4020
|
+
} else {
|
|
4021
|
+
return false;
|
|
4022
|
+
}
|
|
4018
4023
|
};
|
|
4019
4024
|
const enableResendOtp = () => {
|
|
4020
4025
|
setTimeout(() => {
|
|
@@ -4040,39 +4045,42 @@ const OTPInput = React.forwardRef(
|
|
|
4040
4045
|
const otp2 = otpRegex.exec(message)?.[1];
|
|
4041
4046
|
setOTP(otp2 ?? "");
|
|
4042
4047
|
if (otp2) {
|
|
4043
|
-
|
|
4048
|
+
refs.current[otp2?.length - 1]?.focus();
|
|
4044
4049
|
}
|
|
4045
4050
|
});
|
|
4046
4051
|
};
|
|
4047
|
-
const reset = () => {
|
|
4048
|
-
setOTP("");
|
|
4049
|
-
otpRefs.current[0]?.focus();
|
|
4050
|
-
};
|
|
4051
4052
|
React.useImperativeHandle(ref, () => ({
|
|
4052
|
-
reset
|
|
4053
|
+
reset() {
|
|
4054
|
+
setOTP("");
|
|
4055
|
+
refs.current[0]?.focus();
|
|
4056
|
+
},
|
|
4057
|
+
set(newOtp) {
|
|
4058
|
+
setOTP(newOtp);
|
|
4059
|
+
refs.current[newOtp?.length - 1]?.focus();
|
|
4060
|
+
}
|
|
4053
4061
|
}));
|
|
4054
4062
|
const handleChange = (index, value) => {
|
|
4055
4063
|
const regex = /^\d+$/;
|
|
4056
4064
|
if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
|
|
4057
4065
|
const newOTP = `${otp}${value}`;
|
|
4058
4066
|
setOTP(newOTP);
|
|
4059
|
-
|
|
4067
|
+
refs.current[index + 1]?.focus();
|
|
4060
4068
|
} else if (value.length === 0 && index > 0) {
|
|
4061
4069
|
const newOTP = otp.slice(0, -1);
|
|
4062
4070
|
setOTP(newOTP);
|
|
4063
|
-
|
|
4071
|
+
refs.current[index - 1]?.focus();
|
|
4064
4072
|
} else if (value?.length === length) {
|
|
4065
4073
|
setOTP(value);
|
|
4066
|
-
|
|
4074
|
+
refs.current[length - 1]?.focus();
|
|
4067
4075
|
} else {
|
|
4068
4076
|
const newOTP = otp.slice(0, -1);
|
|
4069
4077
|
setOTP(newOTP);
|
|
4070
|
-
|
|
4078
|
+
refs.current[index]?.focus();
|
|
4071
4079
|
}
|
|
4072
4080
|
};
|
|
4073
4081
|
const handleKeyPress = (e, index) => {
|
|
4074
4082
|
if (e.nativeEvent.key === "Backspace" && index > 0) {
|
|
4075
|
-
|
|
4083
|
+
refs.current[index - 1]?.focus();
|
|
4076
4084
|
}
|
|
4077
4085
|
};
|
|
4078
4086
|
useEffect(() => {
|
|
@@ -4108,7 +4116,7 @@ const OTPInput = React.forwardRef(
|
|
|
4108
4116
|
value: otp[index] ? "\u25CF" : "",
|
|
4109
4117
|
placeholder: "",
|
|
4110
4118
|
keyboardType: "numeric",
|
|
4111
|
-
ref: (el) =>
|
|
4119
|
+
ref: (el) => refs.current[index] = el,
|
|
4112
4120
|
returnKeyType: otp.length === length ? "done" : "next",
|
|
4113
4121
|
importantForAutofill: "yes",
|
|
4114
4122
|
textContentType: "oneTimeCode",
|