Skip to content

Commit 693b541

Browse files
creageIgor Vaynberg
authored andcommitted
Improve performance on dropdown detaching
Signed-off-by: Igor Vaynberg <igor.vaynberg@github.com>
1 parent a0f067c commit 693b541

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

select2.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@
483483

484484
prepareOpts: function (opts) {
485485
var element, select, idKey;
486+
487+
opts.elementBody = opts.element.closest("body"); // cache for future access
486488

487489
element = opts.element;
488490

@@ -686,7 +688,11 @@
686688
this.clearPlaceholder();
687689

688690
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
689-
this.dropdown.detach().appendTo(this.opts.element.parents("body")).addClass("select2-drop-active");
691+
if(this.dropdown[0] !== this.opts.elementBody.children().last()[0]) { // ensure our dropdown is the last eleemnt, so the z-index is always respected correctly
692+
this.dropdown.detach().appendTo(this.opts.elementBody);
693+
}
694+
695+
this.dropdown.addClass("select2-drop-active");
690696

691697
this.positionDropdown();
692698

0 commit comments

Comments
 (0)