Skip to content

Fix pagination ellipsis item count shift#695

Merged
zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:fix-pagination-ellipsis-count
Jun 9, 2026
Merged

Fix pagination ellipsis item count shift#695
zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:fix-pagination-ellipsis-count

Conversation

@QDyanbing

@QDyanbing QDyanbing commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

变更内容

  • 在默认分页收缩场景下,当 jump-prev 或 jump-next 出现时同步减少中间页码数量,避免整体分页 item 数量增加。
  • 保持 showLessItems 等其它模式的原有行为,避免扩大改动范围。
  • 更新相关快照和用例,覆盖省略号出现时 item 数量保持稳定的场景。

背景原因

关联 ant-design/ant-design#58270。原逻辑会先渲染页码范围,再在需要时额外插入 jump-prev / jump-next,因此省略号出现后整体 item 数量会变多,带有 quick jumper 等右侧控件时会产生位置抖动。

验证

  • npm run lint
  • npx tsc --noEmit
  • npm test -- --runInBand

Summary by CodeRabbit

Bug Fixes

  • 修复分页组件页码显示逻辑,确保在各种场景下正确显示分页项和跳转选项。

Tests

  • 添加分页组件测试用例,验证页码项数量的稳定性和准确性。

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

总体说明

此 PR 对分页组件的导航跳转项渲染逻辑进行重构,将原先内联的条件判断提取为显式的 hasJumpPrevhasJumpNext 标志,同时在页码区间计算时应用这些标志进行边界调整,最后补充了分页页码项数量的一致性测试。

变更内容

分页跳转导航重构与测试

图层 / 文件 说明
跳转导航条件标志与页码区间调整
src/Pagination.tsx
在页码区间计算后新增 hasJumpPrev/hasJumpNext 判断标志;在 !showLessItems 条件下基于标志对 left/right 边界进行增减调整;随后在控制 jump-prev/jump-next 的插入时使用这些标志,取代原先的内联条件表达式。
分页页码项数量一致性测试
tests/index.test.tsx
新增 pager item count 测试块,对总页数为 1000、启用快速跳转的场景,验证在不同当前页值下分页页码项数量始终为 7,确保重构后的逻辑一致性。

代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

变更涉及分页核心逻辑的重构与条件判断的提取,需要理解页码边界调整与跳转项插入的交互关系;同时需要验证测试覆盖是否充分验证了重构后的行为一致性。

建议审查人员

  • zombieJ
  • MadCcc

诗文

🐇 迅捷的跳转更清晰,
标志提取逻辑显分明,
七页项数永不变,
测试守护每寸境。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地概括了本次变更的主要目的:修复分页椭圆项目计数偏移问题。标题与 PR 目标和代码变更内容高度相关,能够清楚地传达变更的核心意图。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/Pagination.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

tests/index.test.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.06%. Comparing base (3b6d3a6) to head (3380069).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #695      +/-   ##
==========================================
+ Coverage   99.03%   99.06%   +0.02%     
==========================================
  Files           3        3              
  Lines         312      320       +8     
  Branches      140      146       +6     
==========================================
+ Hits          309      317       +8     
  Misses          3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Pagination component to maintain a consistent pager item count when jump buttons are displayed. It introduces hasJumpPrev and hasJumpNext flags to dynamically adjust the range of visible page numbers when showLessItems is disabled. Additionally, a new test suite has been added to verify that the pager item count remains stable across various active pages, and the snapshot tests have been updated accordingly. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@QDyanbing QDyanbing marked this pull request as ready for review June 9, 2026 01:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/index.test.tsx (1)

321-343: 💤 Low value

测试用例覆盖了关键边界场景,逻辑正确。

测试用例有效验证了在默认模式下(showLessItems=false)分页项数量保持为 7 的一致性。currentList 涵盖了起始、中间和末尾的关键边界值。

可考虑补充 showLessItems={true} 场景的测试用例,以验证 PR 描述中提到的"保留其他模式行为"的预期。

💡 可选:补充 showLessItems 场景测试
     it('should keep pager item count when jumpers appear', () => {
       currentList.forEach((current) => {
         const { container, unmount } = render(
           <Pagination
             total={1000}
             current={current}
             onChange={jest.fn()}
             showQuickJumper
           />,
         );

         expect(getPagerItems(container)).toHaveLength(7);
         unmount();
       });
     });
+
+    it('should preserve pager behavior with showLessItems', () => {
+      const lessItemsCurrentList = [1, 2, 3, 50, 98, 99, 100];
+      lessItemsCurrentList.forEach((current) => {
+        const { container, unmount } = render(
+          <Pagination
+            total={1000}
+            current={current}
+            onChange={jest.fn()}
+            showQuickJumper
+            showLessItems
+          />,
+        );
+
+        expect(getPagerItems(container)).toHaveLength(5);
+        unmount();
+      });
+    });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/index.test.tsx` around lines 321 - 343, Add a parallel test block for
the showLessItems mode: replicate getPagerItems and iterate the same currentList
but render <Pagination total={1000} current={current} onChange={jest.fn()}
showQuickJumper showLessItems /> and assert the expected pager item count for
the "less items" behavior (use the same currentList to cover start/middle/end);
reference getPagerItems, Pagination, showQuickJumper, and showLessItems to
locate where to change the render and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/index.test.tsx`:
- Around line 321-343: Add a parallel test block for the showLessItems mode:
replicate getPagerItems and iterate the same currentList but render <Pagination
total={1000} current={current} onChange={jest.fn()} showQuickJumper
showLessItems /> and assert the expected pager item count for the "less items"
behavior (use the same currentList to cover start/middle/end); reference
getPagerItems, Pagination, showQuickJumper, and showLessItems to locate where to
change the render and assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a532cfc-66d8-4d7b-874e-cf7208456e87

📥 Commits

Reviewing files that changed from the base of the PR and between 3b6d3a6 and 3380069.

⛔ Files ignored due to path filters (2)
  • tests/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/Pagination.tsx
  • tests/index.test.tsx

@zombieJ zombieJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zombieJ zombieJ merged commit e638f92 into react-component:master Jun 9, 2026
7 of 8 checks passed
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.

2 participants