issue: Focus is not working after reset #9707
Replies: 8 comments 2 replies
-
I got it, if problem is same? But i need to clear all values and state. |
Beta Was this translation helpful? Give feedback.
-
we can consider to introduce a prop to keep all input references, which means you will have to guarantee that none of the field's inputs will get mutated/removed after resetting. For now, the focus will be ready after the next render cycle which means all inputs get re-registered again. |
Beta Was this translation helpful? Give feedback.
-
I understood but re-register is difficult this case, maybe I can change key prop for form element each reset but I don't know is it logical :) What's the wrong? screen-recorder-sun-jan-01-2023-20-27-18.webm |
Beta Was this translation helpful? Give feedback.
-
can you share a codesandbox with steps to reproduce? |
Beta Was this translation helpful? Give feedback.
-
Actually I updated this codesandbox : https://codesandbox.io/s/rhf-after-reset-focus-problem-0jjb2w 1.Press submit and get error. |
Beta Was this translation helpful? Give feedback.
-
The Reference: https://react-hook-form.com/api/useform/resetfield Could it be possible to use |
Beta Was this translation helpful? Give feedback.
-
The workaround that works for me involves using a
In my case the first input is a of type=text. |
Beta Was this translation helpful? Give feedback.
-
using setTimeout with a 1ms delay to focus the input worked for me. form.reset();
setTimeout(() => form.setFocus("email"), 1); |
Beta Was this translation helpful? Give feedback.
-
Version Number
7.41.3
Codesandbox/Expo snack
https://codesandbox.io/s/rhf-after-reset-focus-problem-0jjb2w
Steps to reproduce
1.Press submit while input is empty and see focus and error.
2.You enter input and delete input, apply step 1 and see focus and error.
3.Press reset button then press submit, the focus is not working.
Expected behaviour
Hi,
I'm using material-ui + RHF+ react-imask at same time for coding custom library.
I'm passing RHF field ref to TextField for focusing and it's working good.
After then i'm passing to input component third-party react-imask component (it's getting ref), not problem, the focusing is working perfect.
But when i used the reset function, i lost the focus behavior.
screen-recorder-sun-jan-01-2023-14-40-07.webm
What browsers are you seeing the problem on?
Firefox, Chrome, Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions