I have the same problem. In some cases I was unable to focus in search input of opened select2.
After some debugging I found that jQuery 3.7.1 tries to fix some unexpected behaviour of focusin
/focusout
event. Here is code with that fix. If you curious, and also brave enough, check it.
That code captures focus
related events on #document
a do some magic with them, which unfortunately leads to select2 won't work.
It could be fixed like this:
/**
* Call this in your document.ready function
*/
function fixSelect2SearchInputWontFocus() {
// on select2:open there is fresh .select2-container
$(window).on('select2:open', () => {
// stop propagation of events up to #document
$('.select2-container').on('focus blur focusin focusout', e => {
e.preventDefault();
e.stopPropagation();
});
// off event is not needed, container is removed on close
});
}