fix(presentation): leave modified pagination clicks to the browser (08-12)

The page links prevented every click, so Ctrl/Cmd/Shift-click changed the page
in place instead of opening a new tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donghyeon-ka
2026-09-27 13:06:01 +09:00
co-authored by Claude Opus 5.5
parent a5fff8f4b7
commit cef6744299
2 changed files with 51 additions and 3 deletions
@@ -267,7 +267,17 @@ function PageLinks({
key={candidate}
onClick={(event) => {
// The owner decides how a page change is applied; the href is for
// open-in-new-tab and copy-link.
// open-in-new-tab and copy-link, so a modified or non-primary
// click stays with the browser (08-12).
if (
event.button !== 0 ||
event.metaKey ||
event.altKey ||
event.ctrlKey ||
event.shiftKey
) {
return;
}
event.preventDefault();
onChange(candidate);
}}
+40 -2
View File
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import { render, screen, within } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { fireEvent, render, screen, within } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { Pagination } from "../../src/presentation/design-system/index.ts";
import { CollectionPage } from "../../src/presentation/templates/index.ts";
@@ -78,3 +78,41 @@ describe("Pagination landmarks", () => {
expect(within(slot).getByRole("group", { name: "Pages" })).toBeVisible();
});
});
// 08-12. A modified click is the browser's (new tab/window), not a page change.
describe("Pagination modified clicks", () => {
function renderWith(onChange: (page: number) => void) {
render(
<Pagination
label="Pages"
nextLabel="Next"
onChange={onChange}
page={1}
pageCount={3}
pageLabel={(candidate) => `Page ${candidate}`}
previousLabel="Previous"
/>,
);
return screen.getByRole("link", { name: "Page 2" });
}
it.each([
["Ctrl", { ctrlKey: true }],
["Cmd", { metaKey: true }],
["Shift", { shiftKey: true }],
["Alt", { altKey: true }],
])("leaves a %s click to the browser", (_, modifier) => {
const onChange = vi.fn();
const link = renderWith(onChange);
const notPrevented = fireEvent.click(link, { button: 0, ...modifier });
expect(notPrevented).toBe(true);
expect(onChange).not.toHaveBeenCalled();
});
it("changes the page on a plain primary click", () => {
const onChange = vi.fn();
const link = renderWith(onChange);
expect(fireEvent.click(link, { button: 0 })).toBe(false);
expect(onChange).toHaveBeenCalledWith(2);
});
});