Skip to content

Commit

Permalink
Autocomplete (Menu): Only traverse through .ui-menu-item elements for…
Browse files Browse the repository at this point in the history
… paging. Fixes #6029 - Autocomplete: Custom item can be activated (and result in error) on PageUp/PageDown key click.
  • Loading branch information
scottgonzalez committed Sep 27, 2010
1 parent 0ccc786 commit dda7bcb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ui/jquery.ui.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,25 @@ $.widget("ui.menu", {
if (this.hasScroll()) {
// TODO merge with no-scroll-else
if (!this.active || this.last()) {
this.activate(event, this.element.children(":first"));
this.activate(event, this.element.children(".ui-menu-item:first"));
return;
}
var base = this.active.offset().top,
height = this.element.height(),
result = this.element.children("li").filter(function() {
result = this.element.children(".ui-menu-item").filter(function() {
var close = $(this).offset().top - base - height + $(this).height();
// TODO improve approximation
return close < 10 && close > -10;
});

// TODO try to catch this earlier when scrollTop indicates the last page anyway
if (!result.length) {
result = this.element.children(":last");
result = this.element.children(".ui-menu-item:last");
}
this.activate(event, result);
} else {
this.activate(event, this.element.children(!this.active || this.last() ? ":first" : ":last"));
this.activate(event, this.element.children(".ui-menu-item")
.filter(!this.active || this.last() ? ":first" : ":last"));
}
},

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

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

// TODO try to catch this earlier when scrollTop indicates the last page anyway
if (!result.length) {
result = this.element.children(":first");
result = this.element.children(".ui-menu-item:first");
}
this.activate(event, result);
} else {
this.activate(event, this.element.children(!this.active || this.first() ? ":last" : ":first"));
this.activate(event, this.element.children(".ui-menu-item")
.filter(!this.active || this.first() ? ":last" : ":first"));
}
},

Expand Down

0 comments on commit dda7bcb

Please sign in to comment.