jquery - JqueryUI Autocomplete item focus does not work using arrow keys -
in jquery autocomplete widget, reason, list items selected using mouse , mouse hover event works apply css , change item background appropriately. when using arrow keys navigate autocomplete list item not focused. default action , populates input box value of item (i have prevented default action not populate input box) item not focused (see screenshot).
css:
.ui-menu-item:hover{ cursor: pointer; background: #d6dff2; }
javascript:
$.widget("ui.autocomplete", $.ui.autocomplete, { options: { maxitems: 2 }, _rendermenu: function (ul, items) { var = this, count = 0; $.each(items, function (index, item) { if (count < that.options.maxitems) { that._renderitemdata(ul, item); } count++; }); } }); var initializeautocomplete = function () { $('#example-links').autocomplete({ source: $('#hidden-action-autocomplete').val(), maxitems: 10, delay: 750, minlength :1, select: function (event, ui) { event.preventdefault(); $(this).val(ui.item.label); window.location = '/path/to/be/shown/' + ui.item.value; }, focus: function (event, ui) { event.preventdefault(); $('.ui-autocomplete > li').attr('title', ui.item.label + '(' + ui.item.value + ')'); } }); }
in screenshot, have pressed down arrow key 3 times , third item should have been focused, it's not.
by default, autocomplete uses following css highlight active element:
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #999999; background: #dadada url("images/ui-bg_glass_75_dadada_1x400.png") 50% 50% repeat-x; font-weight: normal; color: #212121; }
try adding classes own css. in case:
.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { cursor: pointer; background: #d6dff2; }
Comments
Post a Comment