Skip to content

Commit 1560a39

Browse files
committed
Update select2.js
DropDown displayed on the left of select-container if not fit right.
1 parent aa686aa commit 1560a39

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

select2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,13 @@ the specific language governing permissions and limitations under the Apache Lic
886886
height = this.container.outerHeight(false),
887887
width = this.container.outerWidth(false),
888888
dropHeight = this.dropdown.outerHeight(false),
889+
viewPortRight = $(window).scrollLeft() + document.documentElement.clientWidth,
889890
viewportBottom = $(window).scrollTop() + document.documentElement.clientHeight,
890891
dropTop = offset.top + height,
891892
dropLeft = offset.left,
892893
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
893894
enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
895+
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
894896
aboveNow = this.dropdown.hasClass("select2-drop-above"),
895897
bodyOffset,
896898
above,
@@ -917,6 +919,10 @@ the specific language governing permissions and limitations under the Apache Lic
917919
if (!enoughRoomBelow && enoughRoomAbove) above = true;
918920
}
919921

922+
if (!enoughRoomOnRight) {
923+
dropLeft = offset.left + width - dropWidth;
924+
}
925+
920926
if (above) {
921927
dropTop = offset.top - dropHeight;
922928
this.container.addClass("select2-drop-above");

0 commit comments

Comments
 (0)