I'm developing an autocomplete component, but I'm not able to scroll with the arrow keys (down/up), with the mouse it works normally.
I've researched a lot about it and tried to solve this problem with refs, but it didn't work.
const refs = filteredSuggestions.reduce((acc, value) => {
acc[value.id] = React.createRef();
return acc;
}, {});
Place where it is referenced
suggestionsListComponent = (
<ul class="suggestions">
{filteredSuggestions.map((suggestion, index) => {
let className;
if (index === activeSuggestion) {
className = "suggestion-active";
}
return (
<li ref={refs[suggestion.id]} className={className} key={suggestion} onClick={onClick}>
{suggestion}
</li>
);
})}
</ul>
);
The complete code is here: codesandbox
Can anyone help me solve this problem?