dhre-ui-kit 0.0.325 → 0.0.326

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 CHANGED
@@ -4183,22 +4183,25 @@ const OTPInput = React__default["default"].forwardRef(
4183
4183
  }
4184
4184
  }));
4185
4185
  const handleChange = (index, value) => {
4186
- const regex = /^\d+$/;
4187
- if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4188
- const newOTP = `${otp}${value}`;
4189
- setOTP(newOTP);
4190
- refs.current[index + 1]?.focus();
4191
- } else if (value.length === 0 && index > 0) {
4192
- const newOTP = otp.slice(0, -1);
4193
- setOTP(newOTP);
4194
- refs.current[index - 1]?.focus();
4195
- } else if (value?.length === length) {
4196
- setOTP(value);
4197
- refs.current[length - 1]?.focus();
4198
- } else {
4199
- const newOTP = otp.slice(0, -1);
4200
- setOTP(newOTP);
4201
- refs.current[index]?.focus();
4186
+ const specialCharacterRegex = /[^a-zA-Z0-9 ]/;
4187
+ if (value === "" || value?.length > 1 || !specialCharacterRegex.test(value)) {
4188
+ const regex = /^\d+$/;
4189
+ if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4190
+ const newOTP = `${otp}${value}`;
4191
+ setOTP(newOTP);
4192
+ refs.current[index + 1]?.focus();
4193
+ } else if (value.length === 0 && index > 0) {
4194
+ const newOTP = otp.slice(0, -1);
4195
+ setOTP(newOTP);
4196
+ refs.current[index - 1]?.focus();
4197
+ } else if (value?.length === length) {
4198
+ setOTP(value);
4199
+ refs.current[length - 1]?.focus();
4200
+ } else {
4201
+ const newOTP = otp.slice(0, -1);
4202
+ setOTP(newOTP);
4203
+ refs.current[index]?.focus();
4204
+ }
4202
4205
  }
4203
4206
  };
4204
4207
  const handleKeyPress = (e, index) => {