eduardoborges / use-mask-input

✏️ A react Hook for build elegant input masks. Compatible with React Hook Form
https://npmjs.com/package/use-mask-input
267 stars 13 forks source link

Backspace key writes "Ba" or "BB" in the Input when used with Mask "99.999.999-[99]|[aa]" #91

Open matheusfscit opened 2 weeks ago

matheusfscit commented 2 weeks ago

Description:

When using the mask "99.999.999-[99]|[aa]" with the use-mask-input library, pressing the Backspace key results in the word "Backspace" being written into the input. However, since the mask allows only 2 characters for letters, it ends up writing "Ba" or "BB".

Code Example:

<Input
  type="text"
  label={
    <span>
      RG: <span className="text-red-500">*</span>
    </span>
  }
  variant="bordered"
  defaultValue={control._formValues["rg"]}
  isInvalid={!!errors.rg}
  labelPlacement="outside"
  placeholder="xx.xxx.xxx-xx"
  errorMessage={errors.rg?.message as string}
  className="max-w-[40rem]"
  {...registerWithMask("rg", "99.999.999-[99]|[aa]", {
    required: true,
    autoUnmask: true,
  })}
/>

image

Steps to Reproduce:

Use the mask "99.999.999-[99]|[aa]" in an input field. Type a valid RG number. (In Brazil some states RG has letters at the end) Press the Backspace key.

Expected Behavior:

The Backspace key should delete the previous character, not write "Ba" or "BB" into the input field.

Actual Behavior:

Pressing the Backspace key writes "Ba" or "BB" into the input field.

Environment:

Library Version: 3.4.0 I'm using the mask with react-hook-form

This issue seems to occur specifically with masks that include optional letter characters. It prevents proper user experience by inserting unwanted characters when attempting to delete.

Thank you for looking into this issue.

Ilwel commented 5 days ago

for some reason when i use the hook. The Backspace and Delete are write instead erase the input

image image