Hi all,
I just noticed and odd change in the behavior of the focus method in jQuery 3.4.0 compared with 3.3.1, 2.**, and 1.. versions in a specific case when we try to change the focus to the child element in focusin event of its parent. Here is the code and here you can see a code dojo with the issue:
<span>Check the console</span>
<div id="toolbar" tabindex="0">
<a tabIndex="0" id="foo" >foo</a>
</div>
<script>
$(document).ready(function () {
var toolbar = $('#toolbar');
toolbar.on("focusin", function (ev) {
var element = $(this).find("a");
if (element.length) {
element[0].focus();
console.log(document.activeElement)
}
})
toolbar[0].focus();
//toolbar[0].focus(); this works
console.log('With 3.3.1 here we expect to see "foo":', document.activeElement.id);
});
</script>
If we use older version or the native focus() method the issue is not present.
Greetings.
Plamen
@timmywil While I think this issue should be fixed in a patch update to 3.4, IMO #4350 & #4356 are way more serious and it’s been 3 weeks since the 3.4.0 release so I’d rather not postpone 3.4.1 further. We can always do 3.4.2 with a fix for this issue & any other that may pop up in the meantime.