dhre-ui-kit 0.0.324 → 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.mjs CHANGED
@@ -4146,22 +4146,25 @@ const OTPInput = React.forwardRef(
4146
4146
  }
4147
4147
  }));
4148
4148
  const handleChange = (index, value) => {
4149
- const regex = /^\d+$/;
4150
- if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4151
- const newOTP = `${otp}${value}`;
4152
- setOTP(newOTP);
4153
- refs.current[index + 1]?.focus();
4154
- } else if (value.length === 0 && index > 0) {
4155
- const newOTP = otp.slice(0, -1);
4156
- setOTP(newOTP);
4157
- refs.current[index - 1]?.focus();
4158
- } else if (value?.length === length) {
4159
- setOTP(value);
4160
- refs.current[length - 1]?.focus();
4161
- } else {
4162
- const newOTP = otp.slice(0, -1);
4163
- setOTP(newOTP);
4164
- refs.current[index]?.focus();
4149
+ const specialCharacterRegex = /[^a-zA-Z0-9 ]/;
4150
+ if (value === "" || value?.length > 1 || !specialCharacterRegex.test(value)) {
4151
+ const regex = /^\d+$/;
4152
+ if (value.length === 1 && regex.test(value) && index >= 0 && index < length) {
4153
+ const newOTP = `${otp}${value}`;
4154
+ setOTP(newOTP);
4155
+ refs.current[index + 1]?.focus();
4156
+ } else if (value.length === 0 && index > 0) {
4157
+ const newOTP = otp.slice(0, -1);
4158
+ setOTP(newOTP);
4159
+ refs.current[index - 1]?.focus();
4160
+ } else if (value?.length === length) {
4161
+ setOTP(value);
4162
+ refs.current[length - 1]?.focus();
4163
+ } else {
4164
+ const newOTP = otp.slice(0, -1);
4165
+ setOTP(newOTP);
4166
+ refs.current[index]?.focus();
4167
+ }
4165
4168
  }
4166
4169
  };
4167
4170
  const handleKeyPress = (e, index) => {