diff --git a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js index 17202d494a2..47dfc447964 100644 --- a/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js +++ b/app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js @@ -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; } } diff --git a/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js b/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js index 4b83e7a4c51..42ae5ee7836 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/keyboard-shortcuts-test.js @@ -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 = ` + + `; await triggerKeyEvent(document, "keypress", "J"); assert