Skip to content

Commit a7d0849

Browse files
committed
close any opened select2s when the window is scrolled or resized. fixes select2#296 and potentially select2#149
1 parent bc9867a commit a7d0849

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

select2.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@
400400
throw new Error("formatterName must be a function or a falsy value");
401401
}
402402

403+
function evaluate(val) {
404+
return $.isFunction(val) ? val() : val;
405+
}
406+
403407
/**
404408
* blurs any Select2 container that has focus when an element outside them was clicked or received focus
405409
*
@@ -429,9 +433,20 @@
429433
});
430434
});
431435

432-
function evaluate(val) {
433-
return $.isFunction(val) ? val() : val;
434-
}
436+
/**
437+
* Closes any opened Select2s when the window is resized
438+
*/
439+
$(window).resize(debounce(100, function() {
440+
$(".select2-container.select2-dropdown-open").select2('close');
441+
}));
442+
443+
/**
444+
* Closes any opened Select2s when the window is scrolled
445+
*/
446+
$(window).scroll(debounce(100, function() {
447+
$(".select2-container.select2-dropdown-open").select2('close');
448+
}));
449+
435450

436451
/**
437452
* Creates a new class

0 commit comments

Comments
 (0)