]> source.dussan.org Git - jquery-ui.git/commitdiff
Autocomplete: Don't prevent keypress for multiline. Fixed #8911 - Autocomplete: Unabl...
authorJason Moon <jmoon@socialcast.com>
Wed, 20 Mar 2013 22:42:34 +0000 (17:42 -0500)
committerScott González <scott.gonzalez@gmail.com>
Thu, 25 Apr 2013 17:18:11 +0000 (13:18 -0400)
(cherry picked from commit f5f08791536e689e008b04d6ea9677811353d456)

tests/unit/autocomplete/autocomplete_core.js
ui/jquery.ui.autocomplete.js

index c828ffe22f9e782b9472df106ea81ff59e49b863..7b9deb2ab5bd5c189d6559a464b5802cdfdb5b13 100644 (file)
@@ -89,6 +89,30 @@ test( "allow form submit on enter when menu is not active", function() {
        test( "down arrow moves focus - contenteditable", function() {
                arrowsMoveFocus( "#autocomplete-contenteditable", false );
        });
+       
+       test( "up arrow moves cursor - input", function() {
+               arrowsNavigateElement( "#autocomplete", true, false );
+       });
+
+       test( "down arrow moves cursor - input", function() {
+               arrowsNavigateElement( "#autocomplete", false, false );
+       });
+
+       test( "up arrow moves cursor - textarea", function() {
+               arrowsNavigateElement( "#autocomplete-textarea", true, true );
+       });
+
+       test( "down arrow moves cursor - textarea", function() {
+               arrowsNavigateElement( "#autocomplete-textarea", false, true );
+       });
+
+       test( "up arrow moves cursor - contenteditable", function() {
+               arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
+       });
+
+       test( "down arrow moves cursor - contenteditable", function() {
+               arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
+       });
 
        function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
                expect( 1 );
@@ -120,6 +144,23 @@ test( "allow form submit on enter when menu is not active", function() {
                element.autocomplete( "search" );
                element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
        }
+       
+       function arrowsNavigateElement( id, isKeyUp, shouldMove ) {
+               expect( 1 );
+
+               var didMove = false,
+                       element = $( id ).autocomplete({
+                               source: [ "a" ],
+                               delay: 0,
+                               minLength: 0
+                       });
+               element.on( "keypress", function( e ) {
+                       didMove = !e.isDefaultPrevented();
+               });
+               element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
+               element.simulate( "keypress" );
+               equal( didMove, shouldMove, "respond to arrow" );
+       }
 })();
 
 asyncTest( "handle race condition", function() {
index d98eb8c00bf4e4d54297dfa298f032fd3e8f601b..269236a3a66468c50031b240211d6530ab6d0b05 100644 (file)
@@ -142,7 +142,9 @@ $.widget( "ui.autocomplete", {
                        keypress: function( event ) {
                                if ( suppressKeyPress ) {
                                        suppressKeyPress = false;
-                                       event.preventDefault();
+                                       if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
+                                               event.preventDefault();
+                                       }
                                        return;
                                }
                                if ( suppressKeyPressRepeat ) {