Skip to content

[spike] Fix card-list rail pagination on short final page - #4971

Draft
Jimmy cook (jimmycook) wants to merge 1 commit into
mainfrom
spike/card-list-rail-short-final-page-pagination
Draft

[spike] Fix card-list rail pagination on short final page#4971
Jimmy cook (jimmycook) wants to merge 1 commit into
mainfrom
spike/card-list-rail-short-final-page-pagination

Conversation

@jimmycook

Copy link
Copy Markdown
Contributor

Spike

Investigating a pagination bug in BpkCardList row/rail mode.

Problem

When the final page of a rail holds fewer cards than initiallyShownCards (odd totals — e.g. 3 cards shown 2-wide), physically scrolling to the end does not advance the pagination indicator.

Cause: in usePageScrollSync, the page index is derived from Math.floor(firstVisibleIndex / initiallyShownCards). On a short final page there isn't enough content to scroll that page's first card to the viewport start, so firstVisibleIndex never reaches it and the indicator stays on the previous page.

Change

  • BpkCardListRowRail/utils.tsx — in usePageScrollSync, if the last card is visible we've reached the end, so snap the indicator to the final page (totalPages - 1); otherwise the existing calculation is used.
  • BpkCardListRowRail/utils-test.tsx — unit test for the short-final-page case.
  • BpkCardList.stories.tsx — two repro stories:
    • RowToRailShortFinalPage (2-wide, 3 cards)
    • RowToRailShortFinalPageWider (4-wide, 10 cards)

How to review

Storybook → bpk-component-card-list → the two RowToRailShortFinalPage* stories. On desktop, physically scroll to the last card; the indicator now tracks to the final page. pnpm jest packages/backpack-web/src/bpk-component-card-list is green (61 tests).

Notes

Draft / spike — no changelog entry yet, wanted a sanity check on the approach before polishing.

🤖 Generated with Claude Code

When a row/rail's final page holds fewer cards than initiallyShownCards
(odd totals, e.g. 3 cards shown 2-wide), physical scrolling to the end
never advanced the pagination indicator: firstVisibleIndex could not reach
the last page's start card, so Math.floor(firstVisibleIndex / shown) stayed
on the previous page.

Fix: in usePageScrollSync, if the last card is visible we've reached the
end, so snap the indicator to the final page.

Adds two Storybook repro stories (2-wide/3-card and 4-wide/10-card) and a
unit test for the short-final-page case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

Visit https://backpack.github.io/storybook-prs/4971 to see this build running in a browser.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor
Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 27d5d24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant