I have a simple input like that
<input id="name-srch" type="text" data-type="string">
And my js (simplified)
$('#name-srch').autocomplete({
source: function (request, response) {
$.ajax({
url: ...,
data: ...,
success: function (data) {
// note that 'data' is the list of elements to display
response(data)
}
});
},
select: function (event, ui) {
// do some stuff
return false
},
focus: function (event, ui) {
console.log(ui.item.Name) // just to see if the focus event is triggered, and it is
return false
}
})
.autocomplete("instance")._renderItem = function (ul, item) {
return $("<li>")
.append("<a>" + item.Name + "</a>")
.appendTo(ul);
};
JQuery Autocomplete fill the <ul>
with the <li>s
as it should and triggers a focus event on mouseover or down/up arrow key as it should.
The problem is that I want to apply a particular style to the focused item, so in my CSS I have something like that
.ui-state-focus {
background-color: red;
font-weight: bold;
}
There is my problem, the focused item never takes the ui-state-focus
class and therefore it never takes the defined style.
What am I doing wrong :( ?
EDIT : I already tried to add in my CSS something like
.ui-menu-item:hover {
background-color: red;
font-weight: bold;
}
Indeed it does the trick for the hover, but not for the focus via down/up arrow key. Moreover, I don't really like it, I would prefer to make it work the way it's meant to if I can...