Skip to content

Commit c53f7b6

Browse files
committed
Autocomplete: add a selectFirst option
* Default is false (existing behavior) * When true, if the menu is visible but not active and the user hits enter or tab, auto select the first item
1 parent c0f7afd commit c53f7b6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $.widget( "ui.autocomplete", {
2525
autoFocus: true,
2626
delay: 300,
2727
minLength: 1,
28+
selectFirst: false,
2829
position: {
2930
my: "left top",
3031
at: "left bottom",
@@ -87,7 +88,12 @@ $.widget( "ui.autocomplete", {
8788
//passthrough - ENTER and TAB both select the current element
8889
case keyCode.TAB:
8990
if ( !self.menu.active ) {
90-
return;
91+
if ( self.options.selectFirst && self.menu.element.is(":visible") ) {
92+
self._move("next", event);
93+
}
94+
else {
95+
return;
96+
}
9197
}
9298
self.menu.select( event );
9399
break;

0 commit comments

Comments
 (0)