popover_menus: Allow focusing an item when none is focused.

Commit 71fbc93c03 (#34685) incorrectly
removed this behavior.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2025-05-26 15:29:49 -07:00 committed by Tim Abbott
parent ac29ae21da
commit 7eec8fe3a2

View File

@ -77,14 +77,14 @@ export function popover_items_handle_keyboard(key: string, $items?: JQuery): voi
return;
}
if ((key === "down_arrow" || key === "vim_down") && index !== -1) {
if (key === "down_arrow" || key === "vim_down") {
[...$items]
.slice(index + 1)
.slice(index === -1 ? 0 : index + 1)
.find((item) => item.getClientRects().length)
?.focus();
} else if ((key === "up_arrow" || key === "vim_up") && index !== -1) {
} else if (key === "up_arrow" || key === "vim_up") {
[...$items]
.slice(0, index)
.slice(0, index === -1 ? $items.length : index)
.findLast((item) => item.getClientRects().length)
?.focus();
}