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

focusInput(0) not working after render #341

Closed
hrithik73 opened this issue Apr 7, 2022 · 9 comments
Closed

focusInput(0) not working after render #341

hrithik73 opened this issue Apr 7, 2022 · 9 comments

Comments

@hrithik73
Copy link

hrithik73 commented Apr 7, 2022

What I am trying to do:-
I want to click on the label to get focus on the first input field

How I am Doing?
I am using useRef and accesing focusInput() function with arguement 0

Expected Behavior:-
It should focus on the first input
Current Behavior:-
0th Input does not get the focus after rendering but after any changes in any input It works
1,2,3 inputs works fine i want the first one to get focused

Is there any other way to achieve this?
Thanks in advance

@harishydav
Copy link

@hrithik73 It seems to be working just fine.

I came here looking for finding a way to find a way to programmatically focus.
Stumbled across your Codesandbox and realized the code sandbox is actually a good example to learn how to focusInput.

So I guess you can close the issue yourself.
Since you anyways invested effort in creating this you can probably contribute that as an example of focusInput

@hrithik73
Copy link
Author

hrithik73 commented Apr 21, 2022

@harishydav I think on the first render it doesn't work as expected, The expected behavior is to focus on the first input when you click on the label but after some focusing on any input field if you click on the label it works fine as expected

@harishydav
Copy link

@hrithik73 have you tried shouldAutoFocus this will focus the opt-boxes on first render

@hrithik73
Copy link
Author

Yeah , But i need auto focus when clicked on label

@vivek0046
Copy link

any updates on this ?
i am also facing the same issue

@hrithik73
Copy link
Author

hrithik73 commented May 17, 2022

Sadly No :( ,
Our requirement has changed and we dropped the project

@Amethystafyy282
Copy link

any updates on this ? i am also facing the same issue

I've a workaround

            OTPRef.current.focusInput(1);
            setTimeout(() => OTPRef.current.focusInput(0), 1);

@hrithik73
Copy link
Author

any updates on this ? i am also facing the same issue

I've a workaround

            OTPRef.current.focusInput(1);
            setTimeout(() => OTPRef.current.focusInput(0), 1);

It's a good workaround but the UX will not be good as it shows the pointer moving from 2nd position to 1st in real-time.

@ritikbanger

This comment was marked as spam.

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

5 participants