Skip to content

Commit dda7bcb

Browse files
committed
Autocomplete (Menu): Only traverse through .ui-menu-item elements for paging. Fixes #6029 - Autocomplete: Custom item can be activated (and result in error) on PageUp/PageDown key click.
1 parent 0ccc786 commit dda7bcb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,24 +501,25 @@ $.widget("ui.menu", {
501501
if (this.hasScroll()) {
502502
// TODO merge with no-scroll-else
503503
if (!this.active || this.last()) {
504-
this.activate(event, this.element.children(":first"));
504+
this.activate(event, this.element.children(".ui-menu-item:first"));
505505
return;
506506
}
507507
var base = this.active.offset().top,
508508
height = this.element.height(),
509-
result = this.element.children("li").filter(function() {
509+
result = this.element.children(".ui-menu-item").filter(function() {
510510
var close = $(this).offset().top - base - height + $(this).height();
511511
// TODO improve approximation
512512
return close < 10 && close > -10;
513513
});
514514

515515
// TODO try to catch this earlier when scrollTop indicates the last page anyway
516516
if (!result.length) {
517-
result = this.element.children(":last");
517+
result = this.element.children(".ui-menu-item:last");
518518
}
519519
this.activate(event, result);
520520
} else {
521-
this.activate(event, this.element.children(!this.active || this.last() ? ":first" : ":last"));
521+
this.activate(event, this.element.children(".ui-menu-item")
522+
.filter(!this.active || this.last() ? ":first" : ":last"));
522523
}
523524
},
524525

@@ -527,25 +528,26 @@ $.widget("ui.menu", {
527528
if (this.hasScroll()) {
528529
// TODO merge with no-scroll-else
529530
if (!this.active || this.first()) {
530-
this.activate(event, this.element.children(":last"));
531+
this.activate(event, this.element.children(".ui-menu-item:last"));
531532
return;
532533
}
533534

534535
var base = this.active.offset().top,
535536
height = this.element.height();
536-
result = this.element.children("li").filter(function() {
537+
result = this.element.children(".ui-menu-item").filter(function() {
537538
var close = $(this).offset().top - base + height - $(this).height();
538539
// TODO improve approximation
539540
return close < 10 && close > -10;
540541
});
541542

542543
// TODO try to catch this earlier when scrollTop indicates the last page anyway
543544
if (!result.length) {
544-
result = this.element.children(":first");
545+
result = this.element.children(".ui-menu-item:first");
545546
}
546547
this.activate(event, result);
547548
} else {
548-
this.activate(event, this.element.children(!this.active || this.first() ? ":last" : ":first"));
549+
this.activate(event, this.element.children(".ui-menu-item")
550+
.filter(!this.active || this.first() ? ":last" : ":first"));
549551
}
550552
},
551553

0 commit comments

Comments
 (0)