diff --git a/src/presentation/design-system/primitives/navigation.tsx b/src/presentation/design-system/primitives/navigation.tsx index d19b6074..1fac75dc 100644 --- a/src/presentation/design-system/primitives/navigation.tsx +++ b/src/presentation/design-system/primitives/navigation.tsx @@ -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); }} diff --git a/tests/component/pagination.test.tsx b/tests/component/pagination.test.tsx index a6bdc5b0..e4ee9730 100644 --- a/tests/component/pagination.test.tsx +++ b/tests/component/pagination.test.tsx @@ -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( + `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); + }); +});