eduardoborges / use-mask-input

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

Datetime jumping caret lag #87

Open Defite opened 2 months ago

Defite commented 2 months ago

Link to reproduce issue: codesandbox

Steps to reproduce:

1) Type correct date 2) Clear field - "Field is required" is showing 3) Try to type new date

Showcase: Screen Recording 2024-06-22 at 20 12 31

levipadre commented 3 weeks ago

Hi @Defite. I have the same issue. Have you found any solution to this by any chance?

Defite commented 3 weeks ago

Hi @Defite. I have the same issue. Have you found any solution to this by any chance?

Hi. No, I moved on with another library(

Defite commented 3 weeks ago

@Defite which library? I'm having the same issue.

I use react-imask.

thgcst commented 3 weeks ago

@Defite In my case, I was trying to use the currency mask, and had the same caret jumping issue.

I dug into the code and found the problem.

https://github.com/eduardoborges/use-mask-input/blob/d9217a9743c31110c79915e5a176987e9d39428d/src/utils/getMaskOptions.ts#L28

Looks like every time you pass an empty array as the placeholder on inputmask it behaves weirdly. Their doc suggests to use " ". In my case by just passing placeholder: "0" the issue was fixed.

@eduardoborges great lib btw. Brasil representando 🚀

Defite commented 3 weeks ago

@thgcst in my case it didn't helped :( I use it like this:

<input
  {...registerWithMask("date", "datetime", {
    inputFormat: "yyyy-mm-dd",
    placeholder: "0",
    required: "Field is required",
  })}
  type="text"
/>