How to setFocus on first radio input using useController
?
#12006
Unanswered
bartonyoung
asked this question in
General
Replies: 2 comments 1 reply
-
I removed useEffect and used autoFocus on first input https://codesandbox.io/p/sandbox/hook-form-radios-forked-ph33cj |
Beta Was this translation helpful? Give feedback.
0 replies
-
@tatsmaki thanks for the response. I also realized that the reason it was focusing on the last radio is because I passed the same I was trying to avoid |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a Form that is rendering a
RadioGroup
component. TheRadioGroup
component renders three radio inputs and usesuseController
to pass a ref to each. Everything works as expected, except when attempting tosetFocus
from the parent component, it always sets focus on the last radio input. How can I make it focus on the first?Demo code here: https://codesandbox.io/p/sandbox/hook-form-radios-2xrfky?file=%2Fsrc%2FApp.js%3A33%2C34
You may need to refresh the display window to see it focusing on the last radio in the list.
FYI, the
RadioGroup
component mimics the basic pattern of a component I have to use in production, hence my usage ofuseController
.Beta Was this translation helpful? Give feedback.
All reactions