]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Maintain focus on already selected item during typeahead
authorTJ VanToll <tj.vantoll@gmail.com>
Thu, 2 Oct 2014 21:15:07 +0000 (17:15 -0400)
committerTJ VanToll <tj.vantoll@gmail.com>
Fri, 3 Oct 2014 13:30:49 +0000 (09:30 -0400)
Fixes #10644
Closes gh-1354

tests/unit/menu/menu_events.js
ui/menu.js

index 0a02cc01b5f172f790c1b9b65f850279150a3dcf..ff7eb4c7cbcbc1f05c115ec218cfdc289dc832b1 100644 (file)
@@ -629,6 +629,28 @@ asyncTest( "handle keyboard navigation with spelling of menu items", function()
        element[ 0 ].focus();
 });
 
+asyncTest( "Keep focus on selected item (see #10644)", function() {
+       expect( 1 );
+       var element = $( "#menu2" ).menu({
+               focus: function( event ) {
+                       log( $( event.target ).find( ".ui-state-focus" ).index() );
+               }
+       });
+
+       log( "keydown", true );
+       element.one( "menufocus", function() {
+               element.simulate( "keydown", { keyCode: 65 } );
+               element.simulate( "keydown", { keyCode: 68 } );
+               element.simulate( "keydown", { keyCode: 68 } );
+               element.simulate( "keydown", { keyCode: 89 } );
+               element.simulate( "keydown", { keyCode: 83 } );
+               equal( logOutput(), "keydown,0,1,3,3,3",
+                       "Focus stays on 'Addyston', even after other options are eliminated" );
+               start();
+       });
+       element[ 0 ].focus();
+});
+
 test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function() {
        expect( 1 );
        var element = $( "#menu1" ).menu({
index 9664e37efbec18a41c5c5f243580db6450671700..1ecc0ea8cb2c00d37a10f30f09b477b7042c6599 100644 (file)
@@ -251,7 +251,7 @@ return $.widget( "ui.menu", {
 
                        if ( match.length ) {
                                this.focus( event, match );
-                               if ( match.length > 1 ) {
+                               if ( match.length > 0 ) {
                                        this.previousFilter = character;
                                        this.filterTimer = this._delay(function() {
                                                delete this.previousFilter;