Skip to content

Conversation

@Wxh16144
Copy link
Contributor

@Wxh16144 Wxh16144 commented Sep 1, 2025

bg: ant-design/ant-design#54827

fix #355

移除移动端条件判断。在 antd v6 生效。

原来 v4.13.0 至 v5 都不再进行修复改进了

Outdated description

移动端不应该直接去掉 dom,还是允许开发者通过 controls=true 显示dom。并且开发者还可以通过 @media(hover:none) 始终显示。

image

Summary by CodeRabbit

  • 新功能

    • 调整数字输入在不同设备上的步进控制:默认桌面显示、移动端默认隐藏,但可通过属性显式开启;控制逻辑由上层组件决定,改善跨设备体验。
  • 测试

    • 新增移动端用例,验证显式开启时显示步进按钮;补充服务端渲染校验并整理测试结构,提升回归可靠性。

@vercel
Copy link

vercel bot commented Sep 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
input-number Error Error Sep 1, 2025 10:51am

@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

移除 StepHandler.tsx 中基于移动端的渲染拦截逻辑,使组件在所有设备上无条件渲染;同时删除了依赖该行为的移动端相关测试文件 tests/mobile.test.tsx。其余处理步骤、鼠标按下循环与清理逻辑未改动。

Changes

Cohort / File(s) Change Summary
组件渲染逻辑更新
src/StepHandler.tsx
删除 useMobile 引用与移动端判定分支,取消在移动端直接 return null 的行为;其余逻辑未变。
测试移除(与移动端门控相关)
tests/mobile.test.tsx
删除基于 isMobile 的移动端隐藏步进器测试与 SSR 测试用例。

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant S as StepHandler
  participant N as InputNumber

  rect rgba(230, 245, 255, 0.6)
    note right of S: 新行为:不区分设备,始终渲染
    U->>S: 查看组件(移动/桌面)
    S->>U: 渲染步进按钮 +/- 与事件绑定
  end

  U->>S: 按下/长按 +/-
  activate S
  S->>N: 触发步进回调(递增/递减)
  N-->>S: 更新值
  S-->>U: 反映最新值
  deactivate S
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
支持移动端显示并可使用 +/- 步进按钮(#355

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
删除 SSR 相关断言的测试(tests/mobile.test.tsx) 关联测试仅验证移动端隐藏与 SSR 输出包含步进器容器;与问题单仅关注“移动端可用性”一致,非超范围变更。

Poem

小兔敲键叩云端,
步进不再避手机📱—皆可看;
加一减一随手点,
数字跃然轻如烟。
嘀嗒嘀嗒,组件欢——蹦跳到你指尖!


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 23a042e and adc4ef7.

📒 Files selected for processing (1)
  • tests/mobile.test.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/mobile.test.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Summary of Changes

Hello @Wxh16144, 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 组件中增减控件的显示逻辑,特别是针对移动设备。它为这些元素的可见性提供了更灵活的控制,允许开发者在需要时显式地在移动设备上显示它们,而不是无条件隐藏。

Highlights

  • 控件显示逻辑优化: 核心改动是关于增减控件(StepHandler)的显示逻辑,尤其是在移动设备上。
  • 移动端控件可见性: 之前,StepHandler 在移动设备上是无条件隐藏的。现在,StepHandler 的可见性由 mergedControls 变量控制,该变量默认值为 !isMobile,但可以通过 controls 属性显式设置。这意味着 controls=true 将强制在移动设备上显示控件。
  • 代码结构调整: useMobile hook 从 StepHandler.tsx 移动到 InputNumber.tsx,以集中移动检测逻辑。
  • 测试用例更新: mobile.test.tsx 中新增了一个测试用例,用于验证当 controls=true 时,步进控件在移动设备上能正确显示。
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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

@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 旨在优化 InputNumber 组件在移动设备上增减控制器(controls)的显示逻辑。改动后,控制器在移动设备上默认隐藏,但在桌面设备上默认显示,这改善了移动端的默认用户体验。同时,通过 controls 属性,开发者仍然可以显式控制控制器的显示或隐藏,为开发者提供了更大的灵活性。

主要改动分析:

  1. 逻辑上移:将控制器的显示逻辑从 StepHandler 组件上移至 InputNumber 组件。这使得 StepHandler 成为一个纯粹的展示组件,遵循了容器组件与展示组件分离的良好实践,是一次很好的重构。
  2. 动态默认值:通过引入 useMobile hook 来检测移动设备,并结合 ?? 操作符实现了 controls 属性的动态默认值。新的默认行为是:在移动端为 false(隐藏),非移动端为 true(显示)。这个逻辑 const mergedControls = controls ?? !isMobile; 简洁且正确地实现了需求。
  3. 开发者控制:新的实现允许开发者通过传递 controls prop (e.g., controls={true}) 来覆盖默认行为,在移动设备上也能渲染控制器 DOM。这解决了之前在移动端无法显示控制器的问题,并给予了开发者使用 CSS (如 @media(hover:none)) 进行进一步样式控制的能力。
  4. 测试覆盖:添加了新的单元测试 can show steps when set controls to true,有效地验证了新功能。现有的测试也依然通过,保证了原有功能和 SSR 的稳定性。

整体来看,这些改动设计良好,代码清晰,并且有相应的测试覆盖。这是一个高质量的改进。

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 (4)
src/InputNumber.tsx (3)

137-138: controls 默认语义发生变更(移动端默认隐藏)—需要在文档/变更日志中明确说明

之前默认展示步进器,如今在移动端 controls 未显式设置时会隐藏。请在 README/CHANGELOG 标注该行为变化及迁移指引。需要的话我可以起草一段文档。


180-182: mergedControls 逻辑清晰,但可能引发 SSR→移动端水合不一致

SSR 时常量 isMobile 初值多为 false,会服务端输出步进器;移动端客户端水合后又移除,存在结构不一致与潜在水合警告/首帧抖动。可选缓解:

  • 保留 DOM,用 CSS 隐藏(避免删节点),让水合结构一致;或
  • 在文档中提示该差异,并给出“如需一致,请 controls 显式设为 true/false”的建议。

614-623: 条件渲染与“可通过 @media(hover:none) 强制显示”描述不一致

当前在移动端默认不渲染 StepHandler,CSS 无法“强制显示”不存在的 DOM。若要支持 CSS 覆盖,建议默认渲染但用样式隐藏,或新增类似 alwaysRenderControls/renderControlsDom 的开关以“渲染但隐藏”。请确认 PR 目标与实现保持一致。

tests/mobile.test.tsx (1)

21-24: 新增用例覆盖移动端 controls=true 的路径,👍

建议补充:

  • 桌面环境下 controls={false} 时不显示步进器;
  • 移动端 controls 未设置时不显示(已有),设置为 false 也不显示(显式覆盖默认)。
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c1cded6 and 67167e5.

📒 Files selected for processing (3)
  • src/InputNumber.tsx (4 hunks)
  • src/StepHandler.tsx (0 hunks)
  • tests/mobile.test.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • src/StepHandler.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-09-29T06:18:11.993Z
Learnt from: bombillazo
PR: react-component/input-number#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:

  • src/InputNumber.tsx
  • tests/mobile.test.tsx
🔇 Additional comments (4)
src/InputNumber.tsx (1)

24-24: 确认 useMobile 的 SSR 行为与副作用

请确保该 hook 在 SSR 环境返回稳定初值且不触发 useLayoutEffect 警告;并确认它内部依赖的 isMobile 可被测试中的 mock 正确影响。若初值恒为 false,会与客户端首次渲染产生结构差异(见下文水合风险)。

tests/mobile.test.tsx (3)

2-3: 导入调整合理

与新的导出位置保持一致,无功能性问题。


12-12: 纯格式化变动

无须进一步修改。


19-20: SSR 断言可能掩盖水合差异

此断言要求 SSR 输出包含 handler,但在移动端客户端水合后会移除。建议新增一条专门验证“SSR 标记存在但移动端水合后被移除”的用例,或在文档中注明这一差异为预期。

@codecov
Copy link

codecov bot commented Sep 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.97%. Comparing base (c1cded6) to head (adc4ef7).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #719      +/-   ##
==========================================
- Coverage   96.01%   95.97%   -0.05%     
==========================================
  Files           7        7              
  Lines         301      298       -3     
  Branches       79       78       -1     
==========================================
- Hits          289      286       -3     
  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.

@yoyo837
Copy link
Member

yoyo837 commented Sep 1, 2025

这变化有点break,不需要放 feature 吗?

Copy link

@crazyair crazyair left a comment

Choose a reason for hiding this comment

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

不算 breakchange,因为之前传了 controls 是没效果的,现在传的有效果而已


// Mobile user experience is not ideal, so we choose to hide the step controls by default on mobile.
// However, developers can still display them by setting `controls=true`.
const isMobile = useMobile();
Copy link
Member

Choose a reason for hiding this comment

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

都去掉吧,v6 就开发给人用。antd 里 css 藏起来

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯, antd v6 不需要做任何操作了

@Wxh16144 Wxh16144 changed the title fix: improve inc/dec controls logic fix: Remove mobile device detection Sep 1, 2025
@Wxh16144
Copy link
Contributor Author

Wxh16144 commented Sep 1, 2025

不算 breakchange,因为之前传了 controls 是没效果的,现在传的有效果而已

对,上一个解决方案是想 v5 动态默认值 (pc 默认显示,移动端默认隐藏),开发者仍然可以通过 controls 控制总是显示。

考虑到 v5和 v6同时维护的成本最终只考虑在 v6中进行放开。 v5 和 v4 就不发 patch 了

@zombieJ zombieJ merged commit dec0b8c into react-component:master Sep 4, 2025
10 of 11 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.

【问题】在 #239 重构之后如何在移动端使用input-number的-/+呢?是否不支持移动端了?

4 participants