ladybird/Tests/LibWeb/Text/input/focus-chain.html
Luke Wilde bf34b63439 LibWeb: Don't compare the focus chain's GC::Root contents by reference
The focus chain always consists of newly created GC::Root objects, so
the condition always produced `false`. The fix is to use GC::Root's
overloaded operator== method, which compares the pointers of the stored
type.

This fixes Figma dropdowns and context menus instantly disappearing
upon opening them. This is because they become focused when they insert
them. Because of this bug, it would fire blur events all the way up to
and including the window. Figma listens for the blur event on the
window, and when received, it will instantly hide dropdowns and context
menus. The intention behind this seems to be hiding them when the user
clicks off the browser window, or switches tab.
2025-01-30 19:30:44 +01:00

55 lines
1.9 KiB
HTML

<!DOCTYPE html>
<div id="1">
<div id="2">
<div id="3"></div>
</div>
<div id="4">
<div id="5"></div>
</div>
</div>
<script src="include.js"></script>
<script>
test(() => {
function targetToString(target) {
if (target[Symbol.toStringTag] === "Window")
return "window";
return `${target.tagName}#${target.id}`;
}
const div1 = document.getElementById("1");
const div2 = document.getElementById("2");
const div3 = document.getElementById("3");
const div4 = document.getElementById("4");
const div5 = document.getElementById("5");
[window, div1, div2, div3, div4, div5].forEach(focusTarget => {
const focusTargetString = targetToString(focusTarget);
focusTarget.onblur = (event) => {
println(`${focusTargetString} received blur event, target: ${targetToString(event.target)}, currentTarget: ${targetToString(event.currentTarget)}`);
};
focusTarget.onfocus = (event) => {
println(`${focusTargetString} received focus event, target: ${targetToString(event.target)}, currentTarget: ${targetToString(event.currentTarget)}`);
};
focusTarget.onfocusin = (event) => {
println(`${focusTargetString} received focusin event, target: ${targetToString(event.target)}, currentTarget: ${targetToString(event.currentTarget)}`);
};
focusTarget.onfocusout = (event) => {
println(`${focusTargetString} received focusout event, target: ${targetToString(event.target)}, currentTarget: ${targetToString(event.currentTarget)}`);
};
});
println("== div3 focus");
div3.focus();
println("== div5 focus");
div5.focus();
println("== div1 focus");
div1.focus();
println("== window focus");
window.focus();
});
</script>