Autocomplete: Don't prevent keypress for multiline. Fixed #8911 - Autocomplete: Unable to use up/down arrow keys in a textarea (Firefox).

This commit is contained in:
Jason Moon 2013-03-20 17:42:34 -05:00 committed by Scott González
parent cc378433ab
commit f5f0879153
2 changed files with 44 additions and 1 deletions

View File

@ -90,6 +90,30 @@ test( "allow form submit on enter when menu is not active", function() {
arrowsMoveFocus( "#autocomplete-contenteditable", false ); 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 ) { function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
expect( 1 ); expect( 1 );
@ -120,6 +144,23 @@ test( "allow form submit on enter when menu is not active", function() {
element.autocomplete( "search" ); element.autocomplete( "search" );
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); 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() { asyncTest( "handle race condition", function() {

View File

@ -138,7 +138,9 @@ $.widget( "ui.autocomplete", {
keypress: function( event ) { keypress: function( event ) {
if ( suppressKeyPress ) { if ( suppressKeyPress ) {
suppressKeyPress = false; suppressKeyPress = false;
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
event.preventDefault(); event.preventDefault();
}
return; return;
} }
if ( suppressKeyPressRepeat ) { if ( suppressKeyPressRepeat ) {