Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Pagination): the row wraps instead of scrolling the page at large text (#10552)

Cindy Zhangc4455dd503d9
diff --git a/.changeset/pagination-wraps-at-large-text.md b/.changeset/pagination-wraps-at-large-text.md
new file mode 100644
index 0000000000..3aba42abad
--- /dev/null
+++ b/.changeset/pagination-wraps-at-large-text.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `Pagination` wraps its row when its controls don't fit, as at a larger text size on a phone, instead of scrolling the page sideways and pushing Next off-screen. Previous stays first and Next stays last. Beside other content in a flex row, Pagination can now shrink to its widest control and wrap at the default text size too, where it held one line before; give it `flexShrink: 0` through `xstyle` to keep one line there.
+
+@cixzhang
diff --git a/docs/specs/components/Pagination/Pagination.spec.md b/docs/specs/components/Pagination/Pagination.spec.md
index e964bdb8a0..e9bcc8fe14 100644
--- a/docs/specs/components/Pagination/Pagination.spec.md
+++ b/docs/specs/components/Pagination/Pagination.spec.md
@@ -13,6 +13,7 @@ review_triggers: [public-api, behavior, layout, theming, accessibility]
verified_by:
[
packages/core/src/Pagination/Pagination.test.tsx,
+ packages/core/src/Pagination/__tests__/PaginationTextSize.interaction.browser.spec.ts,
packages/core/src/RadioList/__tests__/RadioGroup.a11y.test.tsx,
packages/core/src/RadioList/__tests__/RadioGroup.a11y.chromium.spec.ts,
packages/core/src/hooks/useListFocus.test.tsx,
@@ -122,6 +123,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR12 | Previous, Next, First, and Last name themselves with localized phrases (Previous and Next name the stride when `step` is above 1) and show that name as a tooltip only while available. Their chevrons mirror under RTL. | `architecture:internationalization`; current source and tests |
| FR13 | `isDisabled` blocks every page change and disables every control. A disabled or boundary control MUST stay focusable with `aria-disabled` and keep focus when it becomes unavailable (`spec:AST-085` FR1, FR4, FR7). Implementation gap: dots and the page-size Selector use `aria-disabled`, but the Buttons use their native-disabled path, so a focused Previous, Next, First, or Last that reaches a boundary drops focus. | `spec:AST-085`; current source and tests |
| FR14 | `ref`, `className`, `style`, `xstyle`, `data-testid`, and other base props reach the landmark. A caller's `aria-label` never replaces the computed landmark name (`label`, else the localized default); other caller ARIA props, such as `aria-labelledby`, still reach the landmark. `data-testid` also reaches the input variant's NumberInput as `<id>-input`. | Current tests |
+| FR15 | When its controls do not fit the available width, as at a larger text size, the row wraps onto more lines in reading order, so every control stays on screen (`spec:AST-102` FR4); Previous and First stay first and Next and Last stay last in reading order. Beside other content in a flex row, the landmark can shrink to its widest control and wrap at any text size. | `spec:AST-102` FR4; current source and tests |
### Allowed variation
@@ -264,6 +266,7 @@ does not decide whether it should remain unreachable.
| FR11 | `Pagination.test.tsx` page-size selector cases | With and without `pageSizeOptions` | Evidence gap: the page-size cases only check that the landmark and buttons render, so no test asserts the Selector's presence or absence, `onPageSizeChange`, or the reset to page 1. | `audit:Pagination/behavior` |
| FR12, ORD3 | `Pagination.test.tsx` first/last, step-name, tooltip, and RTL chevron cases | `hasFirstLast` on `compact` and `input`; stride names; RTL | A wrong name, a missing First or Last, a Previous or Next without a tooltip, or a First or Last chevron that does not mirror like Previous and Next fails. Evidence gap: no test asserts the tooltip text, that the tooltip is absent while a control is unavailable, or that the chevrons mirror under RTL. | `audit:Pagination/accessibility` |
| FR13 | `Pagination.test.tsx` disabled-state and boundary cases, asserting native `disabled` on the Buttons as the current gap pending conformance | Disabled; first and last page | A page change while disabled fails. Evidence gap: no test asserts focus kept at a boundary. | `audit:Pagination/accessibility` |
+| FR15 | `PaginationTextSize.interaction.browser.spec.ts` at a 402 px viewport and 100%, 165% and 194% default font size | Pages; narrow viewport; default text size | A page that scrolls sideways, a control off screen, Previous not first or Next not last in reading order, or a second row at 100% fails. | `audit:Pagination/accessibility` |
| PR1, AR1–AR5 | PR1 has no test (evidence gap). AR1 to AR5 are covered by the FR1, FR6, FR7, FR9, FR10, and FR13 rows. | — | — | `audit:Pagination/accessibility` |
| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current targets | Missing, extra, or stale mappings fail repository validation. | `audit:Pagination/theming` |
diff --git a/packages/core/src/Pagination/Pagination.tsx b/packages/core/src/Pagination/Pagination.tsx
index 71ce155470..b6bbaed03a 100644
--- a/packages/core/src/Pagination/Pagination.tsx
+++ b/packages/core/src/Pagination/Pagination.tsx
@@ -183,16 +183,23 @@ export interface PaginationProps extends Omit<
const PAGE_SIZE_SELECTOR_WIDTH = 80;
const styles = stylex.create({
+ // Both rows wrap when their controls do not fit, as at a larger text size,
+ // so no control leaves the screen.
root: {
display: 'flex',
+ flexWrap: 'wrap',
alignItems: 'center',
justifyContent: 'space-between',
gap: spacingVars['--spacing-4'],
},
controls: {
display: 'flex',
+ flexWrap: 'wrap',
alignItems: 'center',
gap: spacingVars['--spacing-1'],
+ // Lets the controls row narrow to the landmark's width, so it wraps
+ // instead of pushing past it.
+ minWidth: 0,
},
compactFirst: {
marginInlineEnd: `calc(-1 * ${spacingVars['--spacing-1']})`,
diff --git a/packages/core/src/Pagination/__tests__/PaginationTextSize.interaction.browser.spec.ts b/packages/core/src/Pagination/__tests__/PaginationTextSize.interaction.browser.spec.ts
new file mode 100644
index 0000000000..053702227d
--- /dev/null
+++ b/packages/core/src/Pagination/__tests__/PaginationTextSize.interaction.browser.spec.ts
@@ -0,0 +1,99 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file PaginationTextSize.interaction.browser.spec.ts
+ * @input The built Pagination stories on a 402 px viewport, at Chromium's
+ * default font size and at 165% and 194% of it (iOS Dynamic Type AX1 and
+ * AX2 relative to the default body size)
+ * @output Real-browser evidence that the row wraps instead of scrolling the
+ * page sideways, keeps Previous first and Next last, and stays on one line
+ * at the default text size
+ * @position Browser proof of Pagination FR15 (AST-102 FR4)
+ */
+
+import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';
+import {
+ DEFAULT_STORYBOOK_DIR,
+ serveStorybook,
+ type StaticServer,
+} from '@astryxdesign/a11y-spec/storybook';
+
+let storybook: StaticServer;
+
+test.beforeAll(async () => {
+ storybook = await serveStorybook(
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
+ );
+});
+
+test.afterAll(async () => {
+ await storybook?.close();
+});
+
+test.skip(
+ ({browserName}) => browserName !== 'chromium',
+ 'Page.setFontSizes is a Chromium DevTools command',
+);
+
+test.use({viewport: {width: 402, height: 874}});
+
+/** Sets the browser's default font size, which rem-based text follows. */
+async function setDefaultFontSize(page: Page, px: number): Promise<void> {
+ const session = await page.context().newCDPSession(page);
+ await session.send('Page.setFontSizes', {
+ fontSizes: {standard: px, fixed: Math.round((px * 13) / 16)},
+ });
+}
+
+async function openPages(page: Page, px: number): Promise<void> {
+ await setDefaultFontSize(page, px);
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=core-pagination--default&viewMode=story`,
+ );
+ await page.locator('nav button').first().waitFor();
+}
+
+/** The landmark's buttons in DOM order, with their boxes. */
+async function readButtons(page: Page) {
+ return page.evaluate(() => ({
+ scrollWidth: document.documentElement.scrollWidth,
+ viewportWidth: document.documentElement.clientWidth,
+ buttons: [
+ ...document.querySelectorAll<HTMLElement>('#storybook-root nav button'),
+ ].map(button => {
+ const box = button.getBoundingClientRect();
+ return {
+ name: button.getAttribute('aria-label') ?? button.textContent ?? '',
+ left: box.left,
+ right: box.right,
+ top: box.top,
+ };
+ }),
+ }));
+}
+
+test('at the default text size the row stays on one line', async ({page}) => {
+ await openPages(page, 16);
+ const {buttons} = await readButtons(page);
+ const tops = new Set(buttons.map(button => Math.round(button.top)));
+ expect(tops.size).toBe(1);
+});
+
+for (const [size, px] of [
+ ['165%', 26],
+ ['194%', 31],
+] as const) {
+ test(`at ${size} text size the row wraps and keeps every control on screen`, async ({
+ page,
+ }) => {
+ await openPages(page, px);
+ const {scrollWidth, viewportWidth, buttons} = await readButtons(page);
+ expect(scrollWidth).toBeLessThanOrEqual(viewportWidth);
+ for (const button of buttons) {
+ expect(button.left, button.name).toBeGreaterThanOrEqual(0);
+ expect(button.right, button.name).toBeLessThanOrEqual(viewportWidth);
+ }
+ expect(buttons[0].name).toMatch(/previous/i);
+ expect(buttons[buttons.length - 1].name).toMatch(/next/i);
+ });
+}