feat(ui): PageUp/PageDown page through every dropdown list, not just the palette

The palette got PageUp/PageDown, and the same crawl stayed everywhere else a list opens under a
control: the sidebar's channel filter, the Plex genre/studio/collection pickers, the filter and sort
menus, submenus of every playlist you own. floating-ui's list navigation has only the arrows and
Home/End.

- `lib/listPaging`: the one definition of a page (the rows wholly in view minus one, a fixed 10 with
  no layout) and of where it lands (stops at both ends, never on a row it may not take, looking back
  toward the start rather than past it). The palette now uses it instead of its own copy, and
  `listNav` takes its scroll-parent helper from here.
- `AnchoredPopover`: one keydown handler on the reference AND the surface, so a combobox (keys on its
  input, `aria-activedescendant`) and a roving menu (keys on the focused row) both page. It runs after
  floating-ui's own, which has by then switched to keyboard modality and scrolls the new row in. A
  disabled row is never the target; a submenu's key does not also page the menu around it; with no
  mounted rows (closed, a hover card, a dialog) the key keeps its native meaning.

Measured in the browser: the channel filter shows 8 rows and pages by 7 with the active row in view
after the scroll; a menu pages to its last row and back, the page behind it does not scroll; the
palette still pages by 11 of its 12 visible rows.
This commit is contained in:
2026-09-13 05:20:53 +02:00
parent 75d89613d0
commit 5274216981
7 changed files with 255 additions and 35 deletions
+11 -25
View File
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { Search } from "lucide-react";
import Modal from "./Modal";
import { closeTopOverlayThenRun } from "../../lib/history";
import { pageStep, pageTarget } from "../../lib/listPaging";
// The app's jump-to bar: one text field over every place you can go and every app-wide thing you can
// do, opened with Ctrl/Cmd+K. It is the "one-layer operation" half of E10 — reaching a channel three
@@ -71,24 +72,6 @@ function rankItem(item: CommandItem, groupLabel: string, words: string[]): Rank
* every keystroke queues one announcement per letter. */
const ANNOUNCE_DELAY_MS = 400;
/** PageUp/PageDown step without layout to measure (jsdom, or a list not painted yet). */
const PAGE_FALLBACK = 10;
/** How far PageUp/PageDown move: the rows that fit in the scrolling list right now, minus one, so the
* row you paged from stays in sight as the new page's edge (a native listbox does the same). Measured
* rather than fixed: the list is 50vh tall and group headings eat into it. With 461 rows and ~11 in
* view, the arrows alone meant forty presses to cross the channel group (E11, owner request). */
function pageStep(list: HTMLElement | null): number {
const box = list?.getBoundingClientRect();
if (!list || !box || box.height === 0) return PAGE_FALLBACK;
let fits = 0;
for (const option of list.querySelectorAll('[role="option"]')) {
const r = option.getBoundingClientRect();
if (r.top >= box.top - 0.5 && r.bottom <= box.bottom + 0.5) fits++;
}
return Math.max(1, fits - 1);
}
export default function CommandPalette({
open,
onClose,
@@ -186,14 +169,17 @@ export default function CommandPalette({
const from = Math.max(activeIndex, 0);
setPicked(flat[(from + step + flat.length) % flat.length]!.id);
} else if (e.key === "PageDown" || e.key === "PageUp") {
// A page at a time, and NO wrap: the arrows wrap because one step past the end is a small,
// obvious move, but a page-sized jump that lands back at the top reads as "it lost my place".
// Home/End stay the field's own (caret to the start/end of the query).
// A page at a time, stopping at the ends (lib/listPaging). The list is 50vh and group headings
// eat into it, so the page is measured. Home/End stay the field's own (caret to the query's ends).
e.preventDefault();
if (flat.length === 0) return;
const step = pageStep(listRef.current) * (e.key === "PageDown" ? 1 : -1);
const to = Math.min(flat.length - 1, Math.max(0, Math.max(activeIndex, 0) + step));
setPicked(flat[to]!.id);
const list = listRef.current;
const step = pageStep(list, list?.querySelectorAll('[role="option"]') ?? []);
const to = pageTarget(
Math.max(activeIndex, 0),
e.key === "PageDown" ? step : -step,
flat.length,
);
if (to !== null) setPicked(flat[to]!.id);
} else if (e.key === "Enter") {
const item = flat[activeIndex];
if (item) {