Skip to content
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

Fix bug where dropdowns pointing upwards were incorrectly positioned #5621

Merged
merged 1 commit into from Aug 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 41 additions & 25 deletions src/js/select2/dropdown/attachBody.js
Expand Up @@ -16,38 +16,16 @@ define([
container.on('open', function () {
self._showDropdown();
self._attachPositioningHandler(container);

// Must bind after the results handlers to ensure correct sizing
self._bindContainerResultHandlers(container);
});

container.on('close', function () {
self._hideDropdown();
self._detachPositioningHandler(container);
});

container.on('results:all', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('results:append', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('results:message', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('select', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('unselect', function () {
self._positionDropdown();
self._resizeDropdown();
});

this.$dropdownContainer.on('mousedown', function (evt) {
evt.stopPropagation();
});
Expand Down Expand Up @@ -89,6 +67,44 @@ define([
this.$dropdownContainer.detach();
};

AttachBody.prototype._bindContainerResultHandlers =
function (decorated, container) {

// These should only be bound once
if (this._containerResultsHandlersBound) {
return;
}

var self = this;

container.on('results:all', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('results:append', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('results:message', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('select', function () {
self._positionDropdown();
self._resizeDropdown();
});

container.on('unselect', function () {
self._positionDropdown();
self._resizeDropdown();
});

this._containerResultsHandlersBound = true;
};

AttachBody.prototype._attachPositioningHandler =
function (decorated, container) {
var self = this;
Expand Down