Unable to set focus programmatically
See original GitHub issueI use a controlled approach, so I store code
in state and reset it in case of a verification error.
const [code, setCode] = useState('')
const codeInputRef = useRef(null)
const onFulfill = (code) => {
setCode('')
codeInputRef.current.focusField(0)
}
render () {
return (
<OTPInputView
ref={innerRef}
autoFocusOnLoad
onCodeFilled={onFulfill}
onCodeChanged={setCode}
code={code}
innerRef={codeInputRef}
/>
)
}
This seems to be working in the simulator, unfortunately it doesn’t work on a real device. Tested on iPhone 11 Pro
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Can't set focus on an input box programmatically in Angular
The problem is that the input element is still hidden when you try to set focus on it. To make sure that the...
Read more >Unable to set focus on lightning-input-field in LWC
The focus() method does not work currently in the LWC Local Web Development Server. You'll need to deploy your code to an org...
Read more >Set focus to input text box with JavaScript/jQuery | Techie Delight
This post will discuss how to set focus on the input text box with ... sets focus only at the page load time...
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
blur() set/unset the focus on the element. For instance, let's make the visitor unable to leave the input if the value is invalid:....
Read more >How to set focus on TextField whic… | Apple Developer Forums
That's because ViewDidAppear occurs later, when all responders are set. Don't forget to mark the thread as closed. Posted 4 years ago by....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The following seems to work:
const currentAppState = useAppState();