Skip to content

Conversation

@guoyunhe
Copy link
Contributor

@guoyunhe guoyunhe commented Nov 3, 2025

避免和原生 type 冲突

Summary by CodeRabbit

发布说明

  • 破坏性变更

    • InputNumber 组件的公有属性 type 已更名为 mode,取值仍为 'input' 或 'spinner',请更新使用处。
    • 与之对应的样式类名已由 -type-spinner 改为 -mode-spinner,影响基于类名的自定义样式。
  • 测试

    • 测试用例已同步改为使用 mode 属性。

@vercel
Copy link

vercel bot commented Nov 3, 2025

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

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @guoyunhe, 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!

此拉取请求主要进行了一项重构,将 InputNumber 组件中用于定义输入框类型的属性从 type 更名为 mode。这一调整是为了解决 type 属性可能与 HTML 原生属性产生命名冲突的问题,从而提高代码的清晰度和可维护性。所有相关的样式、组件用法和测试都已同步更新以反映此更名。

Highlights

  • 属性重命名: 将 InputNumber 组件的 type 属性重命名为 mode
  • 避免原生冲突: 此更改旨在避免与原生 HTML type 属性发生潜在的命名冲突,提高代码的清晰度和可维护性。
  • 全面更新: 所有相关的样式文件、演示代码、组件逻辑和测试快照都已同步更新以反映此更名。
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.

@coderabbitai
Copy link

coderabbitai bot commented Nov 3, 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.

Walkthrough

将 InputNumber 的公共 prop 从 type 重命名为 mode,并同步更新相关样式选择器(-type-spinner-mode-spinner)、演示用例和单元测试,内部逻辑与行为保持不变。

Changes

内聚体 / 文件 变更摘要
样式变更
assets/index.less
CSS 选择器前缀从 -type-spinner 重命名为 -mode-spinner,包括所有嵌套子选择器(-handler, -handler-up, -handler-down)。样式结构未变。
组件 API 更新
src/InputNumber.tsx
公共 prop 从 type?: 'input' | 'spinner' 重命名为 mode?: 'input' | 'spinner',所有条件分支、类名构造和默认值改用 mode。局部 JSX 格式微调,无行为变更。
文档演示
docs/demo/spinner.tsx
三处示例将 type="spinner" 替换为 mode="spinner"
测试用例
tests/props.test.tsx
测试用例将 prop 使用与期望类名由 type="spinner" / rc-input-number-type-spinner 更新为 mode="spinner" / rc-input-number-mode-spinner

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 分钟

需要关注的点:

  • 确认 src/InputNumber.tsx 中所有旧的 type 引用均已替换为 mode(包含类型定义和默认值)。
  • 检查 assets/index.less 的类名修改是否与生成的类名一致(prefixCls-mode-...)。
  • 验证 tests/props.test.tsxdocs/demo/spinner.tsx 中示例与断言同步更新且通过。

Possibly related PRs

Suggested reviewers

  • zombieJ

诗歌

🐰 属性换名跳一跳,
从 type 到 mode 轻轻绕,
样式更新步步好,
测试示例也跟跑,
小兔鼓掌笑眯眯。 🎉

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 该拉取请求的标题为 'fix: type to mode',清晰地描述了本次变更的主要内容——将组件API中的 type 属性重命名为 mode。这与变更集中跨越所有文件(包括InputNumber.tsx、assets/index.less、测试文件和文档示例)的核心改动相符,完全反映了此次变更的目的。标题简洁明了,没有冗余信息,能够让团队成员快速理解这个改动的实质。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 784a500 and 737498d.

📒 Files selected for processing (1)
  • tests/props.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: src/InputNumber.tsx:173-174
Timestamp: 2024-09-29T06:18:11.993Z
Learning: In `src/InputNumber.tsx`, within the `InternalInputNumber` component, the state variables `prevValueRef` and `inputValueRef` are typed as `string | number` to maintain consistency with existing code.
📚 Learning: 2024-10-08T21:56:37.546Z
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: tests/validator.test.tsx:34-83
Timestamp: 2024-10-08T21:56:37.546Z
Learning: In `tests/validator.test.tsx`, the test cases focus on the `validator` function. When the validator condition is not met, the input value should not change. The `formatter` is tested separately in another file.

Applied to files:

  • tests/props.test.tsx
📚 Learning: 2024-09-29T06:18:11.993Z
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: src/InputNumber.tsx:173-174
Timestamp: 2024-09-29T06:18:11.993Z
Learning: In `src/InputNumber.tsx`, within the `InternalInputNumber` component, the state variables `prevValueRef` and `inputValueRef` are typed as `string | number` to maintain consistency with existing code.

Applied to files:

  • tests/props.test.tsx
🔇 Additional comments (1)
tests/props.test.tsx (1)

410-414: 测试更新正确!

prop 重命名(typemode)和对应的 CSS 类名(rc-input-number-type-spinnerrc-input-number-mode-spinner)更新都已正确应用。测试逻辑清晰,与 PR 目标一致。


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
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.01%. Comparing base (15d2f31) to head (737498d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #725   +/-   ##
=======================================
  Coverage   96.01%   96.01%           
=======================================
  Files           7        7           
  Lines         301      301           
  Branches       81       80    -1     
=======================================
  Hits          289      289           
  Misses         12       12           

☔ 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
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

本次 PR 将 type 属性重命名为 mode 以避免与原生 HTML 属性冲突,这是一个很好的改进。代码更改整体上是正确的,并且在所有相关文件中都保持了一致性。我只在测试文件中发现了一个小的命名问题,建议进行修改以提高代码清晰度。

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)
tests/props.test.tsx (1)

410-415: 测试已正确更新以反映新 API。

测试用例正确地使用了 mode="spinner" 并验证生成的类名为 rc-input-number-mode-spinner。建议可以将测试描述从 'type props' 更新为 'mode props' 以保持一致性,但这不是必须的。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15d2f31 and 784a500.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/baseInput.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • assets/index.less (1 hunks)
  • docs/demo/spinner.tsx (3 hunks)
  • src/InputNumber.tsx (8 hunks)
  • tests/props.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: src/InputNumber.tsx:173-174
Timestamp: 2024-09-29T06:18:11.993Z
Learning: In `src/InputNumber.tsx`, within the `InternalInputNumber` component, the state variables `prevValueRef` and `inputValueRef` are typed as `string | number` to maintain consistency with existing code.
📚 Learning: 2024-09-29T06:18:11.993Z
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: src/InputNumber.tsx:173-174
Timestamp: 2024-09-29T06:18:11.993Z
Learning: In `src/InputNumber.tsx`, within the `InternalInputNumber` component, the state variables `prevValueRef` and `inputValueRef` are typed as `string | number` to maintain consistency with existing code.

Applied to files:

  • tests/props.test.tsx
  • src/InputNumber.tsx
  • docs/demo/spinner.tsx
📚 Learning: 2024-10-08T21:56:37.546Z
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: tests/validator.test.tsx:34-83
Timestamp: 2024-10-08T21:56:37.546Z
Learning: In `tests/validator.test.tsx`, the test cases focus on the `validator` function. When the validator condition is not met, the input value should not change. The `formatter` is tested separately in another file.

Applied to files:

  • tests/props.test.tsx
📚 Learning: 2024-10-08T21:56:37.546Z
Learnt from: bombillazo
Repo: react-component/input-number PR: 644
File: src/InputNumber.tsx:393-395
Timestamp: 2024-10-08T21:56:37.546Z
Learning: The `InputNumber` component does not use error states or messages; it is designed to prevent the value from updating if validation fails without displaying additional feedback to the user.

Applied to files:

  • src/InputNumber.tsx
  • docs/demo/spinner.tsx
🧬 Code graph analysis (1)
src/InputNumber.tsx (1)
src/StepHandler.tsx (1)
  • StepHandler (26-114)
🔇 Additional comments (6)
docs/demo/spinner.tsx (1)

23-23: LGTM!演示代码已正确更新。

三处使用场景(受控、非受控、changeOnBlur)都已正确地从 type="spinner" 更新为 mode="spinner",与新的 API 保持一致。

Also applies to: 57-57, 68-68

assets/index.less (1)

137-155: LGTM!CSS 类名已正确更新。

所有样式选择器都已从 -type-spinner 一致地更新为 -mode-spinner,与组件生成的新类名匹配。样式结构和行为保持不变。

src/InputNumber.tsx (4)

67-67: LGTM!公共 API 接口已更新。

type 重命名为 mode 避免了与原生 HTML <input> 元素的 type 属性冲突,这是一个合理的改进。类型定义保持清晰,支持 'input''spinner' 两种模式。


637-667: LGTM!条件渲染逻辑正确实现了两种模式。

代码正确地根据 mode 值实现了不同的布局:

  • mode === 'input':将上下按钮包裹在一个容器中(传统的垂直布局)
  • mode === 'spinner':将下按钮和上按钮分别放置在输入框两侧(内联水平布局)

渲染逻辑清晰且正确。


675-675: LGTM!默认值和 CSS 类名生成已正确实现。

  • 第 675 行:设置默认值为 'input',为未指定该属性的用户提供向后兼容性
  • 第 710 行:CSS 类名生成更新为 ${prefixCls}-mode-${mode},与样式文件中的更新保持一致

Also applies to: 710-710


67-67: 验证完成:所有 type 属性用法已更新,迁移充分彻底。

搜索结果确认代码库中不存在任何 InputNumber 组件仍在使用旧的 type 属性。所有 type= 匹配项均为标准 HTML 元素(<button><input>),与此次破坏性变更无关。

验证范围:

  • ✅ 演示文件(docs/demo/spinner.tsxsimple.tsxdecimal.tsx 等):所有 InputNumber 组件已使用新属性,无旧代码
  • ✅ 测试文件:所有测试中 InputNumber 用法已更新
  • ✅ 源代码:无遗留的 type 属性引用

本次 PR 的属性迁移完全且全面,用户代码需要从 type="spinner"|"input" 更新至 mode="spinner"|"input"

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@afc163 afc163 merged commit fde65a3 into react-component:master Nov 4, 2025
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