Fixed positioning with non-static parents
This fixes an issue with non-static parents (ones that were relatively or absolutely positioned) where the dropdown would be offset by the offset of the parent, so it would almost never line up. This fixes the problem by removing the offset when the parent is not statically positioned, which is what we used to do in older versions of Select2. This closes https://github.com/select2/select2/issues/3303. This closes https://github.com/select2/select2/issues/3614. This closes https://github.com/select2/select2/issues/3672.
This commit is contained in:
parent
393ca4cf7f
commit
c9216b4b96
1 changed files with 9 additions and 1 deletions
10
src/js/select2/dropdown/attachBody.js
vendored
10
src/js/select2/dropdown/attachBody.js
vendored
|
@ -3,7 +3,7 @@ define([
|
||||||
'../utils'
|
'../utils'
|
||||||
], function ($, Utils) {
|
], function ($, Utils) {
|
||||||
function AttachBody (decorated, $element, options) {
|
function AttachBody (decorated, $element, options) {
|
||||||
this.$dropdownParent = options.get('dropdownParent') || document.body;
|
this.$dropdownParent = options.get('dropdownParent') || $(document.body);
|
||||||
|
|
||||||
decorated.call(this, $element, options);
|
decorated.call(this, $element, options);
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,14 @@ define([
|
||||||
top: container.bottom
|
top: container.bottom
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Fix positioning with static parents
|
||||||
|
if (this.$dropdownParent[0].style.position !== 'static') {
|
||||||
|
var parentOffset = this.$dropdownParent.offset();
|
||||||
|
|
||||||
|
css.top -= parentOffset.top;
|
||||||
|
css.left -= parentOffset.left;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isCurrentlyAbove && !isCurrentlyBelow) {
|
if (!isCurrentlyAbove && !isCurrentlyBelow) {
|
||||||
newDirection = 'below';
|
newDirection = 'below';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue