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

issue: Undesired focus on error field after revalidation while using 'watch' #9972

Closed
1 task done
sergeyivanovv89 opened this issue Feb 21, 2023 · 9 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@sergeyivanovv89
Copy link

sergeyivanovv89 commented Feb 21, 2023

Version Number

7.43.1

Codesandbox/Expo snack

https://codesandbox.io/s/rhf-bug-with-focus-on-error-field-after-revalidation-1q19nv

Steps to reproduce

  1. Click on 'Submit' button.
  2. See validation error on both text inputs.
  3. Fill the second input.
  4. See error.

Expected behaviour

The first text input shouldn't be focused after the second one is filled. When 'watch' is not used there's no error.

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Moshyfawn
Copy link
Member

I already mentioned it in #9973, this behaviour is due to the InputField defined inside another component.

As a side note, avoid defining React components inside other components to avoid re-initialization on each parent component render and potentially ref issues (input's ref will be different on each render)

#9973 (comment)

@sergeyivanovv89
Copy link
Author

sergeyivanovv89 commented Feb 21, 2023

@Moshyfawn I've just updated my codesandbox and moved InputField into a separate file and the error still occurs.

@Moshyfawn Moshyfawn reopened this Feb 21, 2023
@bluebill1049
Copy link
Member

Screen.Recording.2023-02-22.at.7.42.57.am.mov

I couldn't reproduce the issue.

@Moshyfawn
Copy link
Member

I couldn't reproduce the issue.

Submit -> Edit 2nd input

@Moshyfawn
Copy link
Member

Sry, I'm currently at work

@bluebill1049
Copy link
Member

no worries, i will look into it.

@bluebill1049
Copy link
Member

This is somewhat related to MUI text filed, I don't think it's a root cause of react hook form. I have switched to a native input and the issue go away, and rmeove const refCallback = useMergeRefs([ref, propRef]); resolve the issue as well.

@bluebill1049 bluebill1049 added the question Further information is requested label Feb 21, 2023
@Moshyfawn
Copy link
Member

This is somewhat related to MUI text filed, I don't think it's a root cause of react hook form. I have switched to a native input and the issue go away, and rmeove const refCallback = useMergeRefs([ref, propRef]); resolve the issue as well.

I was able to repro excluding both MUI & forwardRef: sandbox.

Seem like the behaviour is induced by mode: "all": after the first submission the focus is stolen by every erroneous input in order of appearance. Doesn't happen before the submission.

@bluebill1049 bluebill1049 added status: under investigation aware of this issue and pending for investigation bug Something isn't working and removed question Further information is requested status: under investigation aware of this issue and pending for investigation labels Feb 21, 2023
@bluebill1049
Copy link
Member

thanks a lot @Moshyfawn i will patch it now

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants