Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructing isDirty from formState causing error with cursor-position in masked input #46

Open
Danane84 opened this issue Aug 4, 2023 · 5 comments

Comments

@Danane84
Copy link

Danane84 commented Aug 4, 2023

Hi,

i just bumped into the following bug: Destructing formState: {isDirty} from react hook form's useForm leads to an unexpected left-jump of the cursor position when entering the first value into a masked input, eg. typing 123456 will lead to a value of 234561.

Here is a codesandbox with the error replicated: https://codesandbox.io/p/sandbox/friendly-galois-tzw59m

Please let me know if you need any further information!

Update: I just realized that the same bug occus after a yup validation error was triggered: So if I type something in the masked input, which has a .required() yup-validation rule and then delete the input, when the error is triggered, the cursor-position jumps unexpectedly one to the left.

@eduardoborges
Copy link
Owner

@Danane84 Uh, its a insteresting issue. I will investigate that!

@rafma0
Copy link
Contributor

rafma0 commented Aug 27, 2023

It seems like the cursor goes to the start of your active input on every rerender, also it freezes the mouse hover placeholder if its showing when a rerender happens

output.mp4

In this video I used a Joi validation for testing, like this

volume: Joi.number().min(50).max(100)

I hope this helps someone figure what's happening bc I have no clue 🤣
(and it's the only thing keeping me from using this lib in every project from now on)

My "solution" for now is setting in react-hook-form

reValidateMode: 'onSubmit'

@eduardoborges
Copy link
Owner

It seems like the cursor goes to the start of your active input on every rerender, also it freezes the mouse hover placeholder if its showing when a rerender happens

output.mp4
In this video I used a Joi validation for testing, like this

volume: Joi.number().min(50).max(100)

I hope this helps someone figure what's happening bc I have no clue 🤣 (and it's the only thing keeping me from using this lib in every project from now on)

My "solution" for now is setting in react-hook-form

reValidateMode: 'onSubmit'

Great solution!

@rafma0
Copy link
Contributor

rafma0 commented Aug 29, 2023

@eduardoborges maybe reopen this? revalidate onSubmit works but its different from the default behaviour from react-hook-form which is, after you submit the form, it start revalidating all fields on input change. For me, the default is still the preferred behaviour if we can make it work somehow.

@eduardoborges eduardoborges reopened this Aug 29, 2023
@engylemure
Copy link

engylemure commented Oct 19, 2023

@eduardoborges This issue is related to the recreation of the register and the ref on re-renders of the component that uses the withMaskInput or the useHookFormMask, to fix this it could be necessary to create some kind of hook that will memorize it's usage using as dependencies only the parameters of it https://codesandbox.io/p/sandbox/misty-mountain-5fqg48?file=%2Fsrc%2FApp.tsx%3A39%2C31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants