'input.focus is not a function' when using a custom component as the input.
See original GitHub issuecodepen http://codepen.io/dancoates/pen/JErmeO?editors=0010
steps to replicate
- enter something in autosuggest box
- select item from the list by clicking on it
- there will be an error in the console along the lines of ‘input.focus is not a function’
This seems to happen when using a custom renderInputComponent function that returns a custom input component. It doesn’t seem to actually break the autosuggest but doesn’t focus the input and may cause subtle issues that I haven’t noticed yet.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ref.current.focus() is not a function - Stack Overflow
I'm using react v.16.9.0 My code is this: const handleKeyDown = (e, element, index) => { element ...
Read more >Focus management with Vue refs - Learn web development
Inside your mounted() method, assign your labelInput ref to a variable, and then call the focus() function of the ref. You don't have...
Read more >Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render method. In the typical React dataflow, props are...
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
Read more >How to autofocus using React Hooks - LogRocket Blog
When the form component renders, the reference for the email input will be set. This executes the function we have in the useCallback()...
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
Above is correct, I wanted to give an example using a custom component:
The trick here is
ref={null}otherwise the autosuggest input gets set twice, first to the input then to theTextInputcomponent - and focus blows up.A note for styled-components users who stumble across this. You can’t spread the
inputProps, since the inputProps contains arefattribute that, in styled-components, needs to beinnerRef. Do something along these lines:innerRef={inputProps.ref}