DEV: Fix flakyness of keyboard navigation (#22721)

1. in the test, hiding is now done with css so if element gets rerendered it won't lose the styling
2. the skipping now allows for the `<article>` element itself being hidden
This commit is contained in:
Jarek Radosz 2023-07-21 03:07:48 +02:00 committed by GitHub
parent a53e900671
commit b65b452330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -733,11 +733,13 @@ export default {
newIndex += direction;
article = articles[newIndex];
// Element doesn't exist
if (!article) {
// Element doesn't exist
return;
} else if (article.offsetParent !== null) {
// Element is not hidden
}
// Element is visible
if (article.getBoundingClientRect().height > 0) {
break;
}
}

View File

@ -72,8 +72,12 @@ acceptance("Keyboard Shortcuts - Anonymous Users", function (needs) {
test("j/k navigation skips hidden elements", async function (assert) {
await visit("/t/internationalization-localization/280");
query("#post_2").parentElement.style = "display: none";
query("#post_3").parentElement.style = "display: none";
document.querySelector("#qunit-fixture").innerHTML = `
<style>
#post_2, #post_3 { display: none; }
</style>
`;
await triggerKeyEvent(document, "keypress", "J");
assert