Uncaught TypeError: Cannot read property 'focus' of undefined
See original GitHub issueI met error when I use renderInputComponent
API.
autosuggest.js:698 Uncaught TypeError: Cannot read property 'focus' of undefined
at Object.onSuggestionClick [as onClick] (autosuggest.js:698)
at Item._this.onClick (autosuggest.js:2941)
at Object.ReactErrorUtils.invokeGuardedCallback (react-dom.js:9017)
at executeDispatch (react-dom.js:3006)
at Object.executeDispatchesInOrder (react-dom.js:3029)
at executeDispatchesAndRelease (react-dom.js:2431)
at executeDispatchesAndReleaseTopLevel (react-dom.js:2442)
at Array.forEach (<anonymous>)
at forEachAccumulated (react-dom.js:15423)
at Object.processEventQueue (react-dom.js:2645)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:15
Top Results From Across the Web
"Uncaught TypeError: Cannot read property 'focus' of null ...
javascript - Receiving Error Message: "Uncaught TypeError: Cannot read property 'focus' of null" when trying to call focus() to an element ID - ......
Read more >Cannot read property 'focus' of Null in JavaScript | bobbyhadz
The "Cannot read property 'focus' of null" error occurs when trying to call the focus() method on a null value. To solve the...
Read more >JavaScript error: Cannot read property "focus" of null
I have an issue when applying this Javascript to focus an input. This error appears to me. I have this JavaScript and when...
Read more >Cannot read property 'focus' of null : RG-2080 - YouTrack
main.e88435a8acec14a47dcb.js:28 Uncaught TypeError: Cannot read property 'focus' of null. 1. Is required for 1 Is duplicated by 2.
Read more >Uncaught TypeError: Cannot read property 'focus' of null
Alternatively to be double sure about id can you write a line that alert(document.getElementById(id)); inside your javascript. This should not ...
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
I got this error, but wasn’t using any external library for the input.
What fixed it for me was adding
focusInputOnSuggestionClick={false}
to the AutoSuggest props. Seems like it’s enabled by default and the component lost track of its own ref and errored out.renderInputComponent receives a ref in the component, this needs to be attached to your input component. I’m using MUI and this solves it:
You can do this if you’re using a basic HTML input tag: