Skip to content

Commit f5f0879

Browse files
Jason Moonscottgonzalez
Jason Moon
authored andcommitted
Autocomplete: Don't prevent keypress for multiline. Fixed #8911 - Autocomplete: Unable to use up/down arrow keys in a textarea (Firefox).
1 parent cc37843 commit f5f0879

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

tests/unit/autocomplete/autocomplete_core.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ test( "allow form submit on enter when menu is not active", function() {
8989
test( "down arrow moves focus - contenteditable", function() {
9090
arrowsMoveFocus( "#autocomplete-contenteditable", false );
9191
});
92+
93+
test( "up arrow moves cursor - input", function() {
94+
arrowsNavigateElement( "#autocomplete", true, false );
95+
});
96+
97+
test( "down arrow moves cursor - input", function() {
98+
arrowsNavigateElement( "#autocomplete", false, false );
99+
});
100+
101+
test( "up arrow moves cursor - textarea", function() {
102+
arrowsNavigateElement( "#autocomplete-textarea", true, true );
103+
});
104+
105+
test( "down arrow moves cursor - textarea", function() {
106+
arrowsNavigateElement( "#autocomplete-textarea", false, true );
107+
});
108+
109+
test( "up arrow moves cursor - contenteditable", function() {
110+
arrowsNavigateElement( "#autocomplete-contenteditable", true, true );
111+
});
112+
113+
test( "down arrow moves cursor - contenteditable", function() {
114+
arrowsNavigateElement( "#autocomplete-contenteditable", false, true );
115+
});
92116

93117
function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
94118
expect( 1 );
@@ -120,6 +144,23 @@ test( "allow form submit on enter when menu is not active", function() {
120144
element.autocomplete( "search" );
121145
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
122146
}
147+
148+
function arrowsNavigateElement( id, isKeyUp, shouldMove ) {
149+
expect( 1 );
150+
151+
var didMove = false,
152+
element = $( id ).autocomplete({
153+
source: [ "a" ],
154+
delay: 0,
155+
minLength: 0
156+
});
157+
element.on( "keypress", function( e ) {
158+
didMove = !e.isDefaultPrevented();
159+
});
160+
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
161+
element.simulate( "keypress" );
162+
equal( didMove, shouldMove, "respond to arrow" );
163+
}
123164
})();
124165

125166
asyncTest( "handle race condition", function() {

ui/jquery.ui.autocomplete.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ $.widget( "ui.autocomplete", {
138138
keypress: function( event ) {
139139
if ( suppressKeyPress ) {
140140
suppressKeyPress = false;
141-
event.preventDefault();
141+
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
142+
event.preventDefault();
143+
}
142144
return;
143145
}
144146
if ( suppressKeyPressRepeat ) {

0 commit comments

Comments
 (0)