Skip to content

Commit 39aa17a

Browse files
committed
fixed above/below dropdown opening bug
1 parent 3a830a2 commit 39aa17a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

select2.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,14 @@
736736
viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight,
737737
dropTop = offset.top + height,
738738
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
739-
enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop,
739+
enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
740740
aboveNow = this.dropdown.hasClass("select2-drop-above"),
741741
above,
742742
css;
743743

744+
//console.log("droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow);
745+
//console.log("offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body().scrollTop(), "enough?", enoughRoomAbove);
746+
744747
// always prefer the current above/below alignment, unless there is not enough room
745748

746749
if (aboveNow) {
@@ -814,8 +817,7 @@
814817
if (this.search.val() === " ") { this.search.val(""); }
815818

816819
this.dropdown.addClass("select2-drop-active");
817-
818-
this.positionDropdown();
820+
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
819821

820822
this.updateResults(true);
821823

@@ -826,7 +828,7 @@
826828
this.dropdown.show();
827829
this.ensureHighlightVisible();
828830
this.focusSearch();
829-
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
831+
830832
},
831833

832834
// abstract
@@ -1003,6 +1005,9 @@
10031005
return;
10041006
}
10051007

1008+
// position dropdown before making a potentially long request
1009+
this.positionDropdown();
1010+
10061011
this.resultsPage = 1;
10071012
opts.query({
10081013
term: search.val(),

0 commit comments

Comments
 (0)