I have a JQuery autocomplete text box. I have a CSS style sheet which defines the theme for on-focus (say .custom-focus) and on-hover (say .custom-onhover) elements. The style sheet can change based on the user theme selection. I understand that JQuery autocomplete uses classes like "ui-state-focus" to style auto-suggest elements. I need to replace this class with my own class so that it matches with theme and changing the style sheet changes the entire jquery autocomplete theme. (Hence, I cannot simply override the default autocomplete classes). I've achieved this on-hover through following line of code:
$(element).autocomplete({
source: function (request, response) {...})
focus: function (event, ui) {
event.preventDefault();
// adding this class gives desired result, and show correct styling on hover
$(".ui-autocomplete li a").addClass("custom-onhover");
if (ui != null) {
$(element).val(ui.item.value);
}
});
However, I cannot find a way to get the same experience when the user selects the element through keyboard up/down arrow keys.