aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Moon <jmoon@socialcast.com>2013-03-20 17:42:34 -0500
committerScott González <scott.gonzalez@gmail.com>2013-04-25 13:17:21 -0400
commitf5f08791536e689e008b04d6ea9677811353d456 (patch)
tree8fb30bba573f1761108e6a40965eac72cf9994a6
parentcc378433ab776dee8b75c4ece7df92bfe1300aaf (diff)
downloadjquery-ui-f5f08791536e689e008b04d6ea9677811353d456.tar.gz
jquery-ui-f5f08791536e689e008b04d6ea9677811353d456.zip
Autocomplete: Don't prevent keypress for multiline. Fixed #8911 - Autocomplete: Unable to use up/down arrow keys in a textarea (Firefox).
-rw-r--r--tests/unit/autocomplete/autocomplete_core.js41
-rw-r--r--ui/jquery.ui.autocomplete.js4
2 files changed, 44 insertions, 1 deletions
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js
index 2961cb09a..774c84417 100644
--- a/tests/unit/autocomplete/autocomplete_core.js
+++ b/tests/unit/autocomplete/autocomplete_core.js
@@ -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() {
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js
index 5e798d55d..2f303ca6e 100644
--- a/ui/jquery.ui.autocomplete.js
+++ b/ui/jquery.ui.autocomplete.js
@@ -138,7 +138,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 ) {