Skip to content

Commit ad21d01

Browse files
committed
Check if search input should be focussed when opening
1 parent cbd2a70 commit ad21d01

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

select2.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,17 +1915,19 @@ the specific language governing permissions and limitations under the Apache Lic
19151915

19161916
this.search.val(this.focusser.val());
19171917
}
1918-
this.search.focus();
1919-
// move the cursor to the end after focussing, otherwise it will be at the beginning and
1920-
// new text will appear *before* focusser.val()
1921-
el = this.search.get(0);
1922-
if (el.createTextRange) {
1923-
range = el.createTextRange();
1924-
range.collapse(false);
1925-
range.select();
1926-
} else if (el.setSelectionRange) {
1927-
len = this.search.val().length;
1928-
el.setSelectionRange(len, len);
1918+
if (this.opts.shouldFocusInput(this)) {
1919+
this.search.focus();
1920+
// move the cursor to the end after focussing, otherwise it will be at the beginning and
1921+
// new text will appear *before* focusser.val()
1922+
el = this.search.get(0);
1923+
if (el.createTextRange) {
1924+
range = el.createTextRange();
1925+
range.collapse(false);
1926+
range.select();
1927+
} else if (el.setSelectionRange) {
1928+
len = this.search.val().length;
1929+
el.setSelectionRange(len, len);
1930+
}
19291931
}
19301932

19311933
// initializes search's value with nextSearchTerm (if defined by user)

0 commit comments

Comments
 (0)