I am working on a search component with auto-complete functionality and I am running into some strange behavior. The component consists of an input (SearchInput
) and a list of type-ahead results (SearchResultWrapper
).
Clicking on a type-ahead result should populate the SearchInput
field with the selected result and hide the type-ahead results. Losing focus on the field should also hide the results.
Sample code can be found here: https://jsfiddle.net/chez/h22qfx45/.
The issue comes when you comment in the closeResults
function which is responsible for changing the state of the component to hide the type-ahead results. When this code is activated, the onClick
handler for the SearchResult
is no longer picked up by React.
There is obviously a fundamental concept I am missing here. Is React disconnecting its event listeners from the SearchResult
component since it is hidden?