Skip to content

Autocomplete: Updating position when target is dragged or resized (#6642) #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions ui/jquery.ui.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $.widget( "ui.autocomplete", {
_create: function() {
var self = this,
doc = this.element[ 0 ].ownerDocument,
appendToEl = $( this.options.appendTo || "body", doc ),
suppressKeyPress;

this.valueMethod = this.element[ this.element.is( "input" ) ? "val" : "text" ];
Expand Down Expand Up @@ -170,13 +171,25 @@ $.widget( "ui.autocomplete", {
self._change( event );
}, 150 );
});

// dragging or resizing the appendTo element or any of its descendants should
// cause the menu's position to be recalculated
appendToEl.bind( "drag.autocomplete, resize.autocomplete", function( event ) {
if ( self.menu.element.is(":hidden") ) return;
setTimeout( function() {
self.menu.element.position( $.extend({
of: self.element
}, self.options.position )).zIndex( self.element.zIndex() + 1 );
}, 0 );
});

this._initSource();
this.response = function() {
return self._response.apply( self, arguments );
};
this.menu = $( "<ul></ul>" )
.addClass( "ui-autocomplete" )
.appendTo( $( this.options.appendTo || "body", doc )[0] )
.appendTo( appendToEl )
// prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
.mousedown(function( event ) {
// clicking on the scrollbar causes focus to shift to the body
Expand Down Expand Up @@ -367,7 +380,7 @@ $.widget( "ui.autocomplete", {
this._trigger( "close", event );
}
},

_change: function( event ) {
if ( this.previous !== this._value() ) {
this._trigger( "change", event, { item: this.selectedItem } );
Expand Down