Skip to content

Commit 43e6b86

Browse files
committed
prevent scrollback left on opening. fixes select2#467
1 parent 13c1dcb commit 43e6b86

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

select2.css

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ Version: @@ver@@ Timestamp: @@timestamp@@
223223
white-space: nowrap;
224224
}
225225

226-
.select2-search-hidden {
227-
display: block;
228-
position: absolute;
229-
left: -10000px;
230-
}
231-
232226
.select2-search input {
233227
width: 100%;
234228
height: auto !important;
@@ -619,16 +613,16 @@ disabled look for disabled choices in the results dropdown
619613
}
620614

621615
.select2-offscreen {
622-
border: 0;
623616
clip: rect(0 0 0 0);
624-
height: 1;
617+
width: 1px;
618+
height: 1px;
619+
border: 0;
625620
margin: 0;
626-
overflow: hidden;
627621
padding: 0;
622+
overflow: hidden;
628623
position: absolute;
629-
width: 1;
630-
display:block;
631-
left: -10000px;
624+
outline: none;
625+
left: 0px;
632626
}
633627

634628
.select2-display-none {

select2.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ the specific language governing permissions and limitations under the Apache Lic
17751775
container = this.container,
17761776
dropdown = this.dropdown;
17771777

1778-
this.showSearch(this.opts.minimumResultsForSearch >= 0);
1778+
this.showSearch(false);
17791779

17801780
this.selection = selection = container.find(".select2-choice");
17811781

@@ -2038,12 +2038,13 @@ the specific language governing permissions and limitations under the Apache Lic
20382038
this.highlight(selected);
20392039
}
20402040

2041-
// hide the search box if this is the first we got the results and there are a few of them
2041+
// show the search box if this is the first we got the results and there are enough of them for search
20422042

20432043
if (initial === true) {
20442044
var min=this.opts.minimumResultsForSearch;
2045-
showSearchInput = min < 0 ? false : countResults(data.results) >= min;
2046-
this.showSearch(showSearchInput);
2045+
if (min>=0) {
2046+
this.showSearch(countResults(data.results)>=min);
2047+
}
20472048
}
20482049

20492050
},
@@ -2052,9 +2053,10 @@ the specific language governing permissions and limitations under the Apache Lic
20522053
showSearch: function(showSearchInput) {
20532054
this.showSearchInput = showSearchInput;
20542055

2055-
this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
2056+
this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
2057+
this.dropdown.find(".select2-search").toggleClass("select2-offscreen", !showSearchInput);
20562058
//add "select2-with-searchbox" to the container if search box is shown
2057-
$(this.dropdown, this.container)[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");
2059+
$(this.dropdown, this.container).toggleClass("select2-with-searchbox", showSearchInput);
20582060
},
20592061

20602062
// single

0 commit comments

Comments
 (0)