dhre-ui-kit 0.0.201 → 0.0.202

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.mjs CHANGED
@@ -3911,14 +3911,19 @@ const OTPInput = React.forwardRef(
3911
3911
  }));
3912
3912
  const handleChange = (index, value) => {
3913
3913
  const regex = /^\d+$/;
3914
- if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
3914
+ if (value.length === 1 && // User is typing
3915
+ regex.test(value) && index >= 0 && index < length) {
3915
3916
  const newOTP = `${otp}${value}`;
3916
3917
  setOTP(newOTP);
3917
- refs.current[index + 1]?.focus();
3918
+ if (index + 1 < length) {
3919
+ refs.current[index + 1]?.focus();
3920
+ }
3918
3921
  } else if (value.length === 0 && index > 0) {
3919
3922
  const newOTP = otp.slice(0, -1);
3920
3923
  setOTP(newOTP);
3921
- refs.current[index - 1]?.focus();
3924
+ if (index - 1 >= 0) {
3925
+ refs.current[index - 1]?.focus();
3926
+ }
3922
3927
  } else if (value?.length === length) {
3923
3928
  setOTP(value);
3924
3929
  refs.current[length - 1]?.focus();