From a447b9535eccf46fe6b98f57eb5176708fc906d9 Mon Sep 17 00:00:00 2001 From: James Teh Date: Thu, 24 Nov 2022 02:19:42 +1000 Subject: [PATCH] fix: make shortcuts operate relative to the parent toot (#2229) Previously, if focus was on an element inside a toot instead of the toot itself (e.g. moving to a toot and pressing tab), keyboard commands acted as if no toot was active. In particular, this meant that the arrow keys scrolled to the first visible toot. Fixes #2228. --- src/routes/_components/shortcut/ScrollListShortcuts.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/routes/_components/shortcut/ScrollListShortcuts.html b/src/routes/_components/shortcut/ScrollListShortcuts.html index ce1b3f19..822b2eef 100644 --- a/src/routes/_components/shortcut/ScrollListShortcuts.html +++ b/src/routes/_components/shortcut/ScrollListShortcuts.html @@ -119,7 +119,13 @@ if (!activeElement) { return null } - const activeItem = activeElement.getAttribute('id') + // The user might be focused on an element inside a toot. We want to + // move relative to that toot. + const activeArticle = activeElement.closest('article') + if (!activeArticle) { + return null + } + const activeItem = activeArticle.getAttribute('id') if (!activeItem) { return null }