Skip to content

Commit a4a3eed

Browse files
committed
component stays open after clicking on a native select in IE. fixes select2#1356
1 parent efc609d commit a4a3eed

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

select2.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,22 @@ Version: @@ver@@ Timestamp: @@timestamp@@
124124
cursor: pointer;
125125
}
126126

127+
.select2-drop-undermask {
128+
border: 0;
129+
margin: 0;
130+
padding: 0;
131+
position: absolute;
132+
left: 0;
133+
top: 0;
134+
z-index: 9998;
135+
background-color: transparent;
136+
filter: alpha(opacity=0);
137+
}
138+
127139
.select2-drop-mask {
140+
border: 0;
141+
margin: 0;
142+
padding: 0;
128143
position: absolute;
129144
left: 0;
130145
top: 0;

select2.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ the specific language governing permissions and limitations under the Apache Lic
12021202
scroll = "scroll." + cid,
12031203
resize = "resize."+cid,
12041204
orient = "orientationchange."+cid,
1205-
mask;
1205+
mask, undermask = undefined, maskCss;
12061206

12071207
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
12081208

@@ -1233,18 +1233,42 @@ the specific language governing permissions and limitations under the Apache Lic
12331233
});
12341234
}
12351235

1236+
// ie requires an iframe shim to cover controls like selects
1237+
if($.browser.msie) {
1238+
undermask=$("#select2-drop-undermask");
1239+
if (undermask.length==0) {
1240+
undermask = $(document.createElement("iframe"));
1241+
undermask.attr("src","about:blank");
1242+
undermask.attr("id","select2-drop-undermask").attr("class","select2-drop-undermask");
1243+
undermask.attr("allowTransparency", "true");
1244+
undermask.attr("frameborder", "0");
1245+
undermask.hide();
1246+
undermask.appendTo(this.body());
1247+
}
1248+
}
1249+
1250+
12361251
// ensure the mask is always right before the dropdown
12371252
if (this.dropdown.prev()[0] !== mask[0]) {
12381253
this.dropdown.before(mask);
12391254
}
12401255

1256+
// ensure the undermask is always right before the mask
1257+
if (undermask && mask.prev()[0] !== undermask[0]) {
1258+
mask.before(undermask);
1259+
}
1260+
12411261
// move the global id to the correct dropdown
12421262
$("#select2-drop").removeAttr("id");
12431263
this.dropdown.attr("id", "select2-drop");
12441264

12451265
// show the elements
1246-
mask.css(_makeMaskCss());
1247-
mask.show();
1266+
maskCss=_makeMaskCss();
1267+
1268+
if (undermask) { undermask.css(maskCss).show(); }
1269+
1270+
mask.css(maskCss).show();
1271+
12481272
this.dropdown.show();
12491273
this.positionDropdown();
12501274

@@ -1256,7 +1280,9 @@ the specific language governing permissions and limitations under the Apache Lic
12561280
var that = this;
12571281
this.container.parents().add(window).each(function () {
12581282
$(this).on(resize+" "+scroll+" "+orient, function (e) {
1259-
$("#select2-drop-mask").css(_makeMaskCss());
1283+
var maskCss=_makeMaskCss();
1284+
$("#select2-drop-undermask").css(maskCss);
1285+
$("#select2-drop-mask").css(maskCss);
12601286
that.positionDropdown();
12611287
});
12621288
});
@@ -1283,6 +1309,7 @@ the specific language governing permissions and limitations under the Apache Lic
12831309

12841310
this.clearDropdownAlignmentPreference();
12851311

1312+
$("#select2-drop-undermask").hide();
12861313
$("#select2-drop-mask").hide();
12871314
this.dropdown.removeAttr("id"); // only the active dropdown has the select2-drop id
12881315
this.dropdown.hide();

0 commit comments

Comments
 (0)