FIX: J/K post stream navigation inconsistencies (#16171)

This commit is contained in:
Penar Musaraj 2022-03-14 15:09:19 +01:00 committed by GitHub
parent 839639326c
commit 0400d10907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -661,8 +661,8 @@ export default {
.toArray()
.find((article) =>
direction > 0
? article.getBoundingClientRect().top > offset
: article.getBoundingClientRect().bottom > offset
? article.getBoundingClientRect().top >= offset
: article.getBoundingClientRect().bottom >= offset
);
if (!$selected) {
$selected = $articles[$articles.length - 1];

View File

@ -48,6 +48,27 @@ acceptance("Keyboard Shortcuts - Anonymous Users", function (needs) {
await triggerKeyEvent(document, "keypress", "s".charCodeAt(0));
assert.strictEqual(currentURL(), "/t/keyboard-shortcuts-are-awesome/27331");
});
test("j/k navigation moves selection up/down", async function (assert) {
await visit("/t/this-is-a-test-topic/9");
await triggerKeyEvent(document, "keypress", "j".charCodeAt(0));
assert.ok(
exists(".post-stream .topic-post.selected #post_1"),
"first post is selected"
);
await triggerKeyEvent(document, "keypress", "j".charCodeAt(0));
assert.ok(
exists(".post-stream .topic-post.selected #post_2"),
"pressing j moves selection to next post"
);
await triggerKeyEvent(document, "keypress", "k".charCodeAt(0));
assert.ok(
exists(".post-stream .topic-post.selected #post_1"),
"pressing k moves selection to previous post"
);
});
});
acceptance("Keyboard Shortcuts - Authenticated Users", function (needs) {