feat(palette): PageUp/PageDown move a page of results at a time
The jump-to palette lists every module, channel, playlist, view and action — 461 rows on the owner's account, ~11 of them in view — and the arrows were the only way through it: forty presses to cross the channel group. - PageDown/PageUp step by the rows that fit in the list right now, minus one, so the row you paged from stays in sight at the new page's edge. Measured per press (the list is 50vh and group headings eat into it); a fixed 10 when there is no layout to measure. - Unlike the arrows they stop at the ends instead of wrapping: a page-sized jump that lands back at the top reads as having lost your place. - Home/End stay the text field's own. Measured in the browser: 0 → 10 → 20 rows, stops on row 461, PageUp from the end steps 9 (a group heading is in view), the selected row stays visible throughout.
This commit is contained in:
@@ -262,3 +262,74 @@ describe("CommandPalette · accessibility", () => {
|
||||
expect(status.textContent).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
// Owner request (E11): with 461 rows and ~11 in view, the arrows alone were a slog. PageUp/PageDown
|
||||
// move by what fits in the list, and — unlike the arrows — stop at the ends instead of wrapping.
|
||||
describe("CommandPalette · paging", () => {
|
||||
const many = (): CommandGroup[] => [
|
||||
{
|
||||
id: "rows",
|
||||
label: "Rows",
|
||||
items: Array.from({ length: 12 }, (_, i) => ({
|
||||
id: `r${i}`,
|
||||
label: `Row ${i}`,
|
||||
run: () => {},
|
||||
})),
|
||||
},
|
||||
];
|
||||
const openMany = () => render(<CommandPalette open onClose={() => {}} groups={many()} />);
|
||||
const rect = (top: number, height: number) =>
|
||||
({
|
||||
top,
|
||||
bottom: top + height,
|
||||
height,
|
||||
left: 0,
|
||||
right: 100,
|
||||
width: 100,
|
||||
x: 0,
|
||||
y: top,
|
||||
}) as DOMRect;
|
||||
|
||||
it("pages by the rows in view minus one, and stops at both ends", () => {
|
||||
// The list shows 100px and the rows are 30px tall: 3 fit, so a page is 2 rows.
|
||||
const spy = vi.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function (
|
||||
this: Element,
|
||||
) {
|
||||
if (this.getAttribute("role") === "listbox") return rect(0, 100);
|
||||
const all = [...document.querySelectorAll('[role="option"]')];
|
||||
return rect(all.indexOf(this) * 30, 30);
|
||||
});
|
||||
// Restored in `finally`: a spy left behind by a failing assertion fails every later test too.
|
||||
try {
|
||||
openMany();
|
||||
press("PageDown");
|
||||
expect(selected()).toBe("r2");
|
||||
press("PageDown");
|
||||
expect(selected()).toBe("r4");
|
||||
for (let i = 0; i < 10; i++) press("PageDown");
|
||||
expect(selected()).toBe("r11"); // no wrap to the top
|
||||
press("PageUp");
|
||||
expect(selected()).toBe("r9");
|
||||
for (let i = 0; i < 10; i++) press("PageUp");
|
||||
expect(selected()).toBe("r0");
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("steps a fixed page when there is no layout to measure", () => {
|
||||
openMany();
|
||||
press("PageDown");
|
||||
expect(selected()).toBe("r10");
|
||||
press("PageDown");
|
||||
expect(selected()).toBe("r11");
|
||||
});
|
||||
|
||||
it("leaves Home and End to the text field", () => {
|
||||
openMany();
|
||||
press("PageDown");
|
||||
expect(fireEvent.keyDown(field(), { key: "Home" })).toBe(true); // not preventDefault-ed
|
||||
expect(fireEvent.keyDown(field(), { key: "End" })).toBe(true);
|
||||
expect(selected()).toBe("r10");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user