Skip to content

Removing a focused element from the tree doesn't reset focus #26900

@jdm

Description

@jdm
<body>
  <style>div:focus { color: red; }</style>
  <div tabindex=0 id="a" style="background-color: green; width: 100px; height: 100px;"><button onclick="this.parentNode.remove()">remove</button><p>hello</p></div>
<script>
let div = document.querySelector('#a');
div.focus();
div.onkeydown = (e) => { console.log('div down ' + e.key); };
div.onkeyup = (e) => { console.log('div up ' + e.key); };
document.body.onkeydown = function(e) {
  console.log("body down " + e.key);
};
document.body.onkeyup = function(e) {
  console.log("body up " + e.key);
};
</script>

In Firefox, when I press a, then click the remove button and press a again, I see:

div down a
body down a
div up a
body up a
body down a
body up a

Which indicates that the focus was reset such that the div that was removed from the tree is no longer focused.
In Servo, doing the same gives me:

div down a
body down a
div up a
body up a
div down a
div up a

Which indicates that we don't reset the focus when the div is removed from the tree.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions