Skip to content

Commit

Permalink
Autocomplete: Append menu to body and reset z-index on every suggestion.
Browse files Browse the repository at this point in the history
Fixes #5271.
  • Loading branch information
scottgonzalez committed Mar 11, 2010
1 parent 8cd7129 commit 5f21357
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

(function($) {

module("autocomplete: core");
module("autocomplete: core", {
teardown: function() {
$( ":ui-autocomplete" ).autocomplete( "destroy" );
}
});

test("close-on-blur is properly delayed", function() {
var ac = $("#autocomplete").autocomplete({
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
(function($) {

module("autocomplete: events");
module("autocomplete: events", {
teardown: function() {
$( ":ui-autocomplete" ).autocomplete( "destroy" );
}
});

var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"];

Expand Down
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
(function($) {


module("autocomplete: methods");
module("autocomplete: methods", {
teardown: function() {
$( ":ui-autocomplete" ).autocomplete( "destroy" );
}
});

test("destroy", function() {
var beforeHtml = $("#autocomplete").parent().html();
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
(function($) {

module("autocomplete: options");
module("autocomplete: options", {
teardown: function() {
$( ":ui-autocomplete" ).autocomplete( "destroy" );
}
});


/* disabled until autocomplete actually has built-in support for caching
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/autocomplete/autocomplete_tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
(function($) {

module("autocomplete: tickets");
module("autocomplete: tickets", {
teardown: function() {
$( ":ui-autocomplete" ).autocomplete( "destroy" );
}
});



Expand Down
11 changes: 7 additions & 4 deletions ui/jquery.ui.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ $.widget( "ui.autocomplete", {
delay: 300
},
_create: function() {
var self = this;
var self = this,
doc = this.element[ 0 ].ownerDocument;
this.element
.addClass( "ui-autocomplete-input" )
.attr( "autocomplete", "off" )
Expand Down Expand Up @@ -95,7 +96,7 @@ $.widget( "ui.autocomplete", {
};
this.menu = $( "<ul></ul>" )
.addClass( "ui-autocomplete" )
.appendTo( this.element.parent() )
.appendTo( "body", doc )
.menu({
focus: function( event, ui ) {
var item = ui.item.data( "item.autocomplete" );
Expand All @@ -112,7 +113,7 @@ $.widget( "ui.autocomplete", {
self.close( event );
self.previous = self.element.val();
// only trigger when focus was lost (click on menu)
if ( self.element[0] != document.activeElement ) {
if ( self.element[0] !== doc.activeElement ) {
self.element.focus();
}
}
Expand Down Expand Up @@ -232,7 +233,9 @@ $.widget( "ui.autocomplete", {

_suggest: function( items ) {
var self = this,
ul = this.menu.element.empty();
ul = this.menu.element
.empty()
.zIndex( this.element.zIndex() + 1 );
this._renderMenu( ul, items );
// TODO refresh should check if the active item is still in the dom, removing the need for a manual deactivate
this.menu.deactivate();
Expand Down

0 comments on commit 5f21357

Please sign in to comment.