Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdm opened this issue Jun 12, 2020 · 1 comment
Closed

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

jdm opened this issue Jun 12, 2020 · 1 comment

Comments

@jdm
Copy link
Member

@jdm jdm commented Jun 12, 2020

<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.

@jdm jdm mentioned this issue Jun 12, 2020
4 of 4 tasks complete
bors-servo added a commit that referenced this issue Jun 12, 2020
Focus correctness improvements

These changes improve the behaviour of focus in Hubs rooms, and are expected to improve web compat around other dynamic pages that receive keyboard events as well.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26901 and fix #26900.
- [x] There are tests for these changes
bors-servo added a commit that referenced this issue Jun 13, 2020
Focus correctness improvements

These changes improve the behaviour of focus in Hubs rooms, and are expected to improve web compat around other dynamic pages that receive keyboard events as well.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26901 and fix #26900.
- [x] There are tests for these changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
@jdm and others
You can’t perform that action at this time.