I am currently utilizing typeahead.js to generate a basic dropdown list.
The functionality I am aiming for is the ability for users to navigate through suggestions using the keyboard's down key and select a suggestion with the mouse. In both scenarios, the selected suggestion should be highlighted appropriately.
However, I am encountering an issue where both hovered states and selections made by scrolling with the arrow keys are being highlighted simultaneously.
This discrepancy is clearly demonstrated in the animated image provided below.
https://i.sstatic.net/y6Wnf.gif
To highlight hovered states, I have implemented the following CSS:
.tt-suggestion:hover {
color: #f0f0f0;
background-color: #0097cf;
}
For highlighting selections made while scrolling with the arrow keys, I've utilized the following CSS:
.tt-cursor {
color: #f0f0f0;
background-color: #0097cf;
}
Please note: The class .tt-cursor
is automatically added to the suggestion div when scrolled to and removed when navigated away from.
For a better understanding of the situation, you can refer to this CodePen.
My implementation involves a rails backend, with most of the handling done through Javascript & jQuery.
Edit: To clarify further, I am looking to highlight only one suggestion at a time when it is either hovered over or scrolled to, instead of having multiple suggestions highlighted concurrently.