Skip to content

Commit 224f347

Browse files
committed
fix: keep the page number in pagination link names
1 parent b477ab8 commit 224f347

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎src/resources/projects/website/listing/quarto-listing.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,13 @@ function decoratePagination(listingId) {
177177
itemEl.setAttribute("aria-hidden", "true");
178178
continue;
179179
}
180+
const pageNumber = linkEl.getAttribute("data-i");
181+
// A translation may drop the placeholder; keep the number in the name.
180182
linkEl.setAttribute(
181183
"aria-label",
182-
pageLabel.replace("{0}", linkEl.getAttribute("data-i"))
184+
pageLabel.includes("{0}")
185+
? pageLabel.replace("{0}", pageNumber)
186+
: `${pageLabel} ${pageNumber}`
183187
);
184188
if (itemEl.classList.contains("active")) {
185189
linkEl.setAttribute("aria-current", "page");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Label Override Test
3+
language:
4+
listing-page-number: "Page"
5+
listing:
6+
- id: override
7+
contents: posts
8+
type: default
9+
page-size: 1
10+
sort: title
11+
---
12+
13+
## Posts
14+
15+
::: {#override}
16+
:::

‎tests/integration/playwright/tests/listing-pagination.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, Page, test } from "@playwright/test";
22

33
const fixture = "./listings/pagination/_site/index.html";
4+
const overrideFixture = "./listings/pagination/_site/override.html";
45
const singleFixture = "./listings/pagination/_site/single.html";
56

67
// Link texts of each listing; the active page is wrapped in brackets.
@@ -188,6 +189,15 @@ test.describe("Listing pagination accessibility", () => {
188189
).toHaveAttribute("aria-current", "page");
189190
});
190191

192+
test("a page label without {0} still ends with the page number", async ({ page }) => {
193+
await page.goto(overrideFixture);
194+
await expect(nav(page, "override").locator("li.active")).toBeVisible();
195+
const links = nav(page, "override").getByRole("link");
196+
await expect(links.first()).toHaveAccessibleName("Page 1");
197+
await expect(links.nth(1)).toHaveAccessibleName("Page 2");
198+
await expect(links.nth(2)).toHaveAccessibleName("Page 3");
199+
});
200+
191201
// With five listings on one page, every nav shares one label, so axe reports
192202
// landmark-unique. The single-listing page below checks that rule too.
193203
// region: the skip link sits outside any landmark, which has nothing to do

0 commit comments

Comments
 (0)