@@ -102,8 +102,10 @@ $.widget( "ui.autocomplete", {
102
102
focus : function ( event , ui ) {
103
103
var item = ui . item . data ( "item.autocomplete" ) ;
104
104
if ( false !== self . _trigger ( "focus" , null , { item : item } ) ) {
105
- // use value to match what will end up in the input
106
- self . element . val ( item . value ) ;
105
+ // use value to match what will end up in the input, if it was a key event
106
+ if ( / ^ k e y / . test ( event . originalEvent . type ) ) {
107
+ self . element . val ( item . value ) ;
108
+ }
107
109
}
108
110
} ,
109
111
selected : function ( event , ui ) {
@@ -286,7 +288,7 @@ $.widget( "ui.autocomplete", {
286
288
this . menu . deactivate ( ) ;
287
289
return ;
288
290
}
289
- this . menu [ direction ] ( ) ;
291
+ this . menu [ direction ] ( event ) ;
290
292
} ,
291
293
292
294
widget : function ( ) {
@@ -350,15 +352,15 @@ $.widget("ui.menu", {
350
352
. addClass ( "ui-corner-all" )
351
353
. attr ( "tabindex" , - 1 )
352
354
// mouseenter doesn't work with event delegation
353
- . mouseenter ( function ( ) {
354
- self . activate ( $ ( this ) . parent ( ) ) ;
355
+ . mouseenter ( function ( event ) {
356
+ self . activate ( event , $ ( this ) . parent ( ) ) ;
355
357
} )
356
358
. mouseleave ( function ( ) {
357
359
self . deactivate ( ) ;
358
360
} ) ;
359
361
} ,
360
362
361
- activate : function ( item ) {
363
+ activate : function ( event , item ) {
362
364
this . deactivate ( ) ;
363
365
if ( this . hasScroll ( ) ) {
364
366
var offset = item . offset ( ) . top - this . element . offset ( ) . top ,
@@ -375,7 +377,7 @@ $.widget("ui.menu", {
375
377
. addClass ( "ui-state-hover" )
376
378
. attr ( "id" , "ui-active-menuitem" )
377
379
. end ( ) ;
378
- this . _trigger ( "focus" , null , { item : item } ) ;
380
+ this . _trigger ( "focus" , event , { item : item } ) ;
379
381
} ,
380
382
381
383
deactivate : function ( ) {
@@ -388,12 +390,12 @@ $.widget("ui.menu", {
388
390
this . active = null ;
389
391
} ,
390
392
391
- next : function ( ) {
392
- this . move ( "next" , "li:first" ) ;
393
+ next : function ( event ) {
394
+ this . move ( "next" , "li:first" , event ) ;
393
395
} ,
394
396
395
- previous : function ( ) {
396
- this . move ( "prev" , "li:last" ) ;
397
+ previous : function ( event ) {
398
+ this . move ( "prev" , "li:last" , event ) ;
397
399
} ,
398
400
399
401
first : function ( ) {
@@ -404,25 +406,25 @@ $.widget("ui.menu", {
404
406
return this . active && ! this . active . next ( ) . length ;
405
407
} ,
406
408
407
- move : function ( direction , edge ) {
409
+ move : function ( direction , edge , event ) {
408
410
if ( ! this . active ) {
409
- this . activate ( this . element . children ( edge ) ) ;
411
+ this . activate ( event , this . element . children ( edge ) ) ;
410
412
return ;
411
413
}
412
414
var next = this . active [ direction ] ( ) ;
413
415
if ( next . length ) {
414
- this . activate ( next ) ;
416
+ this . activate ( event , next ) ;
415
417
} else {
416
- this . activate ( this . element . children ( edge ) ) ;
418
+ this . activate ( event , this . element . children ( edge ) ) ;
417
419
}
418
420
} ,
419
421
420
422
// TODO merge with previousPage
421
- nextPage : function ( ) {
423
+ nextPage : function ( event ) {
422
424
if ( this . hasScroll ( ) ) {
423
425
// TODO merge with no-scroll-else
424
426
if ( ! this . active || this . last ( ) ) {
425
- this . activate ( this . element . children ( ":first" ) ) ;
427
+ this . activate ( event , this . element . children ( ":first" ) ) ;
426
428
return ;
427
429
}
428
430
var base = this . active . offset ( ) . top ,
@@ -437,18 +439,18 @@ $.widget("ui.menu", {
437
439
if ( ! result . length ) {
438
440
result = this . element . children ( ":last" ) ;
439
441
}
440
- this . activate ( result ) ;
442
+ this . activate ( event , result ) ;
441
443
} else {
442
- this . activate ( this . element . children ( ! this . active || this . last ( ) ? ":first" : ":last" ) ) ;
444
+ this . activate ( event , this . element . children ( ! this . active || this . last ( ) ? ":first" : ":last" ) ) ;
443
445
}
444
446
} ,
445
447
446
448
// TODO merge with nextPage
447
- previousPage : function ( ) {
449
+ previousPage : function ( event ) {
448
450
if ( this . hasScroll ( ) ) {
449
451
// TODO merge with no-scroll-else
450
452
if ( ! this . active || this . first ( ) ) {
451
- this . activate ( this . element . children ( ":last" ) ) ;
453
+ this . activate ( event , this . element . children ( ":last" ) ) ;
452
454
return ;
453
455
}
454
456
@@ -464,9 +466,9 @@ $.widget("ui.menu", {
464
466
if ( ! result . length ) {
465
467
result = this . element . children ( ":first" ) ;
466
468
}
467
- this . activate ( result ) ;
469
+ this . activate ( event , result ) ;
468
470
} else {
469
- this . activate ( this . element . children ( ! this . active || this . first ( ) ? ":last" : ":first" ) ) ;
471
+ this . activate ( event , this . element . children ( ! this . active || this . first ( ) ? ":last" : ":first" ) ) ;
470
472
}
471
473
} ,
472
474
0 commit comments