fix: stabilize pagination nav width to prevent layout shift on page change#1435
Open
octo-patch wants to merge 1 commit intoWei-Shaw:mainfrom
Open
fix: stabilize pagination nav width to prevent layout shift on page change#1435octo-patch wants to merge 1 commit intoWei-Shaw:mainfrom
octo-patch wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1363
Problem
The pagination component's
<nav>element changes width when navigating between pages, causing a visible layout "jump". This happens because the number of rendered page buttons is variable:« 1 2 3 … 23 »→ 5 page items« 1 … 4 5 6 7 8 … 23 »→ 9 page itemsThe old
visiblePagesalgorithm usedpage ± 2as a sliding window, producing between 5 and 9 items depending on the current page, causing the nav to grow and shift other layout elements.Solution
Replace the variable-width algorithm with one that always returns exactly 7 items when
totalPages > 7:page ≤ 41 2 3 4 5 … totalpage ≥ total - 31 … t-4 t-3 t-2 t-1 t1 … p-1 p p+1 … totalThis ensures the
<nav>maintains a constant width regardless of which page the user is on, eliminating the layout shift.Testing
Verified the output length of
visiblePagesis stable across all pages for a 23-page dataset by manually tracing the algorithm:[1,2,3,4,5,'...',23]→ 7 items ✓[1,'...',4,5,6,'...',23]→ 7 items ✓[1,'...',11,12,13,'...',23]→ 7 items ✓[1,'...',19,20,21,22,23]→ 7 items ✓[1,'...',19,20,21,22,23]→ 7 items ✓