Skip to content

Conversation

@ansabamane
Copy link

@ansabamane ansabamane commented Nov 10, 2025

What problem does this PR solve?

Related to ant-design/ant-design#55637

Currently, the QuickJumper page input fields accept any characters (letters, symbols, etc.), which can cause confusion when users accidentally type non-numeric characters.

What is changed and how it works?

  • User can specify the input type for the QuickJumper either of number or text
  • By default, the input type is text

Summary by CodeRabbit

发行说明

  • 改进功能
    • 快速跳转输入框现已限制仅接受数字输入,提升了用户体验和输入准确性。

@vercel
Copy link

vercel bot commented Nov 10, 2025

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Nov 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

概览

将快速跳转输入框的类型从文本改为数字,并相应更新测试用例以验证新的输入行为和值处理逻辑。

变更

内聚体 / 文件 变更摘要
输入类型变更
src/Options.tsx
将快速跳转输入框的 HTML 属性从 type="text" 改为 type="number"
测试更新
tests/jumper.test.tsx
更新两个失焦相关的测试用例预期值,从空字符串改为 null。新增 "inputType number" 测试套件,包含验证数字字符串接受和非数字输入拒绝的两个测试。

代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟

  • 输入类型更改为单行修改,易于验证
  • 测试更新遵循一致的模式,主要是预期值的调整
  • 无复杂逻辑或边界情况需要深入分析

🐰 数字之门已开启,
文本不复见踪迹,
数数字有了新家园,
测试齐声来贺喜,
快速跳跃更精准!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确反映了PR的主要变更——为QuickJumper添加指定输入类型的选项。标题具体、清晰且与代码变更完全相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ansabamane, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new configuration option for the QuickJumper component, allowing developers to explicitly define the input type as either 'text' or 'number'. This change aims to improve the user experience by preventing non-numeric character entry in the page navigation input field, thereby reducing potential confusion and input errors. The update includes modifications to type definitions, component logic to handle the new prop, and corresponding documentation examples.

Highlights

  • New inputType Option for QuickJumper: Introduced a new inputType property within the showQuickJumper configuration, allowing developers to specify whether the QuickJumper input field should accept 'text' (default) or 'number' type input.
  • Improved User Experience: This enhancement addresses the issue where the QuickJumper input previously accepted any characters, potentially causing confusion. By setting inputType to 'number', users can be guided to enter only numeric values for page navigation.
  • Type Definition Updates: The src/interface.ts file has been updated to define QuickJumperOptions and modify the showQuickJumper prop to accept this new type, ensuring type safety and clarity for the new configuration.
  • Component Logic Integration: The Options and Pagination components have been updated to correctly process and apply the inputType prop to the underlying HTML input element, defaulting to 'text' if not explicitly specified.
  • Documentation Examples: New examples have been added to docs/examples/jumper.tsx and docs/examples/jumperWithGoButton.tsx to demonstrate how to use the inputType: 'number' option for the QuickJumper.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces a valuable feature by allowing the input type of the QuickJumper to be specified, enhancing user experience by preventing non-numeric inputs when desired. The changes are well-structured, including updates to interfaces, component props, and the addition of relevant examples. However, I've identified a couple of areas for improvement in src/Pagination.tsx. Firstly, the new inputType is not applied to the simple mode pager, leading to incomplete functionality. Secondly, there's an opportunity to enhance type safety by avoiding the use of as any. My specific comments below provide details and suggestions for these points.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Pagination.tsx (1)

394-404: 简单模式中的输入类型不一致。

简单模式(simple mode)中的输入框硬编码为 type="text"(第 395 行),而普通模式通过 Options 组件支持配置 inputType。这种不一致可能会让用户感到困惑,因为他们无法在简单模式下使用 inputType: 'number' 配置。

建议在简单模式中也支持 inputType 配置:

         {isReadOnly ? (
           internalInputVal
         ) : (
           <input
-            type="text"
+            type={inputType || 'text'}
             aria-label={locale.jump_to}
             value={internalInputVal}
             disabled={disabled}
             onKeyDown={handleKeyDown}
             onKeyUp={handleKeyUp}
             onChange={handleKeyUp}
             onBlur={handleBlur}
             size={3}
           />
         )}

这样可以确保两种模式下的行为一致。

🧹 Nitpick comments (1)
src/Options.tsx (1)

163-163: 考虑 HTML input type="number" 的用户体验影响。

需要注意 HTML <input type="number"> 的一些特性:

  • 允许输入 'e', '+', '-', '.' 等字符(科学计数法)
  • 在某些浏览器中会显示上下箭头控件
  • 输入非数字字符时,e.target.value 可能返回空字符串

您可能需要考虑以下替代方案以获得更好的用户体验:

  • 使用 type="text" 配合 inputMode="numeric"pattern="[0-9]*" 来在移动设备上显示数字键盘,同时避免 type="number" 的副作用
  • 或者在文档中说明 type="number" 的行为特性

是否需要我生成一个替代实现方案的示例?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ffdf47 and e14f458.

📒 Files selected for processing (5)
  • docs/examples/jumper.tsx (1 hunks)
  • docs/examples/jumperWithGoButton.tsx (2 hunks)
  • src/Options.tsx (3 hunks)
  • src/Pagination.tsx (2 hunks)
  • src/interface.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
docs/examples/jumper.tsx (1)
docs/examples/utils/commonUtil.tsx (1)
  • PaginationWithSizeChanger (33-45)
🔇 Additional comments (8)
docs/examples/jumper.tsx (1)

40-50: 示例代码正确展示了新功能。

这个新示例有效地演示了 inputType: 'number' 的用法,与文件中其他示例的结构保持一致。

src/Options.tsx (2)

30-30: 类型定义正确。

新增的 inputType 属性类型定义合理,支持 'text' 和 'number' 两种值。


48-48: 默认值保持向后兼容。

inputType 默认设置为 'text' 确保了向后兼容性,这是一个明智的选择。

src/interface.ts (2)

23-26: 类型定义清晰准确。

新增的 QuickJumperOptions 类型定义结构良好,清楚地表达了快速跳转功能的配置选项,包括可选的 goButtoninputType 字段。


49-49: 改进了类型安全性。

showQuickJumper 的类型从 boolean | object 更新为 boolean | QuickJumperOptions 提供了更好的类型安全性和 IDE 自动补全支持,这是一个很好的改进。

docs/examples/jumperWithGoButton.tsx (2)

25-27: 格式化改进了可读性。

showQuickJumper 对象展开为多行格式提高了代码的可读性,特别是当添加更多属性时。


41-47: 示例有效展示了组合用法。

这个新示例很好地展示了 goButtoninputType: 'number' 的组合使用,为用户提供了实用的参考。

src/Pagination.tsx (1)

600-600: 正确传递了 inputType 属性。

inputType 属性被正确地传递给 Options 组件,实现了普通模式下的功能。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/jumper.test.tsx (3)

276-293: 增强测试以验证 input 属性和完整的导航流程。

当前测试仅检查输入值是否被接受,但未验证:

  1. input 元素是否实际具有 type="number" 属性
  2. 输入有效数字后的页面导航行为(例如按 Enter 键或点击 go 按钮)

建议增强测试:

  it('should accept only number', () => {
    const onChange = jest.fn();
    const { container } = render(
      <Pagination
        onChange={onChange}
        defaultCurrent={1}
        total={95}
        pageSize={10}
        showQuickJumper={{ inputType: 'number' }}
      />,
    );
    const quickJumper = container.querySelector(
      '.rc-pagination-options-quick-jumper',
    );
    const input = quickJumper.querySelector('input');
+   expect(input).toHaveAttribute('type', 'number');
    fireEvent.change(input, { target: { value: '42' } });
    expect(input.value).toBe('42');
+   fireEvent.keyUp(input, { key: 'Enter', keyCode: 13, which: 13 });
+   expect(onChange).toHaveBeenCalledWith(5, 10);
  });

注意:预期页码为 5,因为 total=95, pageSize=10,第 42 页超出范围(最多 10 页),应该跳转到有效页码。请根据实际实现调整预期值。


295-312: 验证 type 属性以确保测试的是组件行为而非浏览器行为。

当前测试依赖浏览器对 type="number" 的原生验证行为(浏览器会自动拒绝非数字输入)。为确保测试验证的是组件正确设置了 input 类型,应显式检查 type 属性。

应用此差异以增强测试:

  it('should not accept non-number', () => {
    const onChange = jest.fn();
    const { container } = render(
      <Pagination
        onChange={onChange}
        defaultCurrent={1}
        total={95}
        pageSize={10}
        showQuickJumper={{ inputType: 'number' }}
      />,
    );
    const quickJumper = container.querySelector(
      '.rc-pagination-options-quick-jumper',
    );
    const input = quickJumper.querySelector('input');
+   expect(input).toHaveAttribute('type', 'number');
    fireEvent.change(input, { target: { value: 'abc' } });
    expect(input.value).toBe('');
  });

275-313: 考虑添加额外的测试用例以提高覆盖率。

当前测试套件验证了 inputType: 'number' 的基本行为。为了更全面的测试覆盖,可以考虑添加:

  1. 默认行为测试(不指定 inputType 时应默认为 'text')
  2. 显式 inputType: 'text' 的测试
  3. 边缘情况(如小数、负数等)

示例测试:

it('should default to text input type', () => {
  const { container } = render(
    <Pagination defaultCurrent={1} total={95} showQuickJumper />
  );
  const input = container.querySelector('.rc-pagination-options-quick-jumper input');
  expect(input).toHaveAttribute('type', 'text');
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e14f458 and b79c609.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • docs/examples/jumper.tsx (1 hunks)
  • tests/jumper.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/examples/jumper.tsx

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.03%. Comparing base (7ffdf47) to head (4e891da).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #664   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files           3        3           
  Lines         310      310           
  Branches      139      139           
=======================================
  Hits          307      307           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Options.tsx (1)

161-161: 实现与 PR 描述不一致,但考虑使用 inputMode 作为更优方案

根据 PR 描述,原本计划添加一个可配置的选项来指定输入类型。然而,当前实现直接硬编码为 type="number"。虽然从过往评论来看,维护者和贡献者已就此方案达成一致,但 PR 描述需要更新以反映实际实现。

关于 type="number" 的一些注意事项:

  • 允许输入 eE(科学计数法)、+-.(小数点),这些对于页码输入并无意义
  • 在桌面端会显示上下调节按钮(spinners),可能影响用户体验
  • 在移动端会显示数字键盘(这是优点)

建议的替代方案:

考虑使用 inputMode="numeric" 配合 type="text"pattern 属性,这样可以:

  • 在移动端显示数字键盘
  • 避免桌面端的调节按钮
  • 通过 pattern 严格限制只能输入纯数字
  • 不允许 eE+-. 等字符
-          type="number"
+          type="text"
+          inputMode="numeric"
+          pattern="[0-9]*"

这种方式在保持移动端数字键盘优势的同时,提供了更精确的输入控制。不过鉴于当前方案已获维护者认可,此建议可作为未来优化考虑。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 258b733 and 4e891da.

⛔ Files ignored due to path filters (3)
  • tests/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/options.test.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/simple.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/Options.tsx (1 hunks)
  • tests/jumper.test.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/jumper.test.tsx

@ansabamane ansabamane requested a review from afc163 November 11, 2025 12:15
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