Any luck with this? Im experiencing the exact same thing.
I used the following:
document.addEventListener('focus', function() {
console.log('focused: ', document.activeElement)
}, true);
To see what was happening with the focus and this was the output on the console:
focused: <input class="select2-search__field" type="search" tabindex="0" autocorrect="off" autocapitalize="none" spellcheck="false" role="searchbox" aria-autocomplete="list" autocomplete="off" aria-label="Search" aria-controls="select2-student_id-results">
custom.js:2
focused: <span class="select2-selection select2-selection--single form-control" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-disabled="false" aria-labelledby="select2-student_id-container" aria-controls="select2-student_id-container" aria-owns="select2-student_id-results">…</span> flex
custom.js:2
focused: <input class="select2-search__field" type="search" tabindex="0" autocorrect="off" autocapitalize="none" spellcheck="false" role="searchbox" aria-autocomplete="list" autocomplete="off" aria-label="Search" aria-controls="select2-student_id-results">
custom.js:2
focused: <span class="select2-selection select2-selection--single form-control" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-disabled="false" aria-labelledby="select2-student_id-container" aria-controls="select2-student_id-container" aria-owns="select2-student_id-results">…</span> flex
The search field is focused then immediately loses focus to the selection container (whether or not anything has yet been selected)
I tried downgrading to jQuery 3.5.1 but the issue persisted.