serenity
serenity copied to clipboard
Ladybird: focus events are not fired when focus is moved via keyboard navigation
JavaScript focus events (both focus
and blur
) do not fire when the focus moves from an element to another via standard keyboard navigation (pressing Tab
or Shift+Tab
).
For example, if a page with the following HTML contents is open in Ladybird, onfocusHandler2
is not called if I click on the text box and then press Tab
to move to the number input.
<!DOCTYPE html>
<html>
<head>
<title>Test page with two inputs</title>
</head>
<body>
<input id="input1" type="text" onblur="onblurHandler1(event)" onfocus="onfocusHandler1(event)">
<input id="input2" type="number" onblur="onblurHandler2(event)" onfocus="onfocusHandler2(event)">
<pre id="con"></pre>
<script>
var con = document.getElementById('con');
function id(elem) { return elem == null ? '(null)' : elem.id; }
function onblurHandler1(event) {
con.innerHTML += `<p>onblurHandler1: target = #${id(event.target)}, relatedTarget = #${id(event.relatedTarget)}</p>`;
}
function onblurHandler2(event) {
con.innerHTML += `<p><b>onblurHandler2: target = #${id(event.target)}, relatedTarget = #${id(event.relatedTarget)}</b></p>`;
}
function onfocusHandler1(event) {
con.innerHTML += `<p>onfocusHandler1: target = #${id(event.target)}, relatedTarget = #${id(event.relatedTarget)}</p>`;
}
function onfocusHandler2(event) {
con.innerHTML += `<p><b>onfocusHandler2: target = #${id(event.target)}, relatedTarget = #${id(event.relatedTarget)}</b></p>`;
}
</script>
</body>
</html>
Although the bug covers focus
and blur
, I suspect that the focusin
and focusout
events may be affected too.
Demonstration
At 0:16, I click outside the first input
element and the onblurHandler1
function is called. However, if I click again on that element and then press Tab
twice, neither onblurHandler1
, onblurHandler2
or onfocusHandler2
is called, although the focus moves to and then out of the second input
.
https://github.com/SerenityOS/serenity/assets/47182594/f301d75f-4e3d-4a8a-bcb4-0cddb9fcaf8b