start();
}
});
+test( "up arrow invokes search - input", function() {
+ arrowsInvokeSearch( "#autocomplete", true, true );
+});
+
+test( "down arrow invokes search - input", function() {
+ arrowsInvokeSearch( "#autocomplete", false, true );
+});
+
+test( "up arrow invokes search - textarea", function() {
+ arrowsInvokeSearch( "#autocomplete-textarea", true, false );
+});
+
+test( "down arrow invokes search - textarea", function() {
+ arrowsInvokeSearch( "#autocomplete-textarea", false, false );
+});
+
+test( "up arrow moves focus - input", function() {
+ arrowsMoveFocus( "#autocomplete", true );
+});
+
+test( "down arrow moves focus - input", function() {
+ arrowsMoveFocus( "#autocomplete", false );
+});
+
+test( "up arrow moves focus - textarea", function() {
+ arrowsMoveFocus( "#autocomplete-textarea", true );
+});
+
+test( "down arrow moves focus - textarea", function() {
+ arrowsMoveFocus( "#autocomplete-textarea", false );
+});
+
+function arrowsInvokeSearch( id, isKeyUp, shouldMove ) {
+ expect( 1 );
+
+ var didMove = false,
+ element = $( id ).autocomplete({
+ source: [ "a" ],
+ delay: 0,
+ minLength: 0
+ });
+ element.data( "autocomplete" )._move = function() {
+ didMove = true;
+ };
+ element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
+ equal( didMove, shouldMove, "respond to arrow" );
+}
+
+function arrowsMoveFocus( id, isKeyUp ) {
+ expect( 1 );
+
+ var didMove = false,
+ element = $( id ).autocomplete({
+ source: [ "a" ],
+ delay: 0,
+ minLength: 0
+ });
+ element.data( "autocomplete" )._move = function() {
+ ok( true, "repsond to arrow" );
+ };
+ element.autocomplete( "search" );
+ element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
+}
}( jQuery ) );
var self = this,
doc = this.element[ 0 ].ownerDocument,
suppressKeyPress;
+ this.isMultiLine = this.element.is( "textarea" );
this.element
.addClass( "ui-autocomplete-input" )
self._move( "nextPage", event );
break;
case keyCode.UP:
- self._move( "previous", event );
- // prevent moving cursor to beginning of text field in some browsers
- event.preventDefault();
+ self._keyEvent( "previous", event );
break;
case keyCode.DOWN:
- self._move( "next", event );
- // prevent moving cursor to end of text field in some browsers
- event.preventDefault();
+ self._keyEvent( "next", event );
break;
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
widget: function() {
return this.menu.element;
+ },
+ _keyEvent: function( keyEvent, event ) {
+ if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
+ this._move( keyEvent, event );
+
+ // prevents moving cursor to beginning/end of the text field in some browsers
+ event.preventDefault();
+ }
}
});