Skip to content

fix: do not trigger onStep when readOnly or disabled - #764

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/readonly-onstep
Dec 2, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/readonly-onstep

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

onStep is called when the input is readOnly or disabled, although the value can't change:

<InputNumber readOnly defaultValue={1} onStep={fn} />
// ArrowUp, or mouseDown on the up handler: fn(1, { type: 'up', ... })

With a handler held down it repeats on every tick, and disabled does the same. The README describes onStep as "Triggered when the value changes by step", and onChange is already suppressed in both states.

onInternalStep only checked the min/max bounds; it now returns early when readOnly || disabled.

Test: an it.each over readOnly and disabled in tests/props.test.tsx covering the handler's mouseDown and ArrowUp/ArrowDown; 2 of the new cases fail without the change. The full suite (192 tests) and tsc pass, and lint has no errors.

An AI coding assistant (Claude Code) helped me find and fix this; I reviewed the change and the tests.

Summary by CodeRabbit

  • Bug Fixes
    • 修复只读或禁用状态下,点击步进按钮或使用方向键仍会触发步进操作的问题。
  • Tests
    • 增加对只读和禁用状态下步进操作行为的验证。

@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown

@mokshupadhyay is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

InputNumber 在只读或禁用状态下会忽略步进操作,并保留原有的范围限制检查。新增测试验证上下按钮和键盘方向键不会触发 onStep。

Changes

步进状态保护

Layer / File(s) Summary
步进状态检查与测试
src/InputNumber.tsx, tests/props.test.tsx
onInternalStep 在 readOnly 或 disabled 时忽略步进,同时保留上下限检查。测试覆盖上下按钮和方向键操作,并断言 onStep 未被调用。

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: zombiej

Merge Risk: Minimal · up to 97680

InputNumber no longer fires onStep when it is readOnly or disabled, so the callback matches the fact that the value cannot change. The change is small and covered by tests, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: do not trigger onStep when readOnly or disabled”准确描述了主要变更。PR 使 InputNumber 在 readOnly 或 disabled 状态下忽略步进操作,不再触发 onStep。raw_summary 显示 src/InputNumber.tsx 的步进处理在只读或禁用状态下提前返回,tests/props.test.ts…
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.
Full details: Title check

Explanation

标题“fix: do not trigger onStep when readOnly or disabled”准确描述了主要变更。PR 使 InputNumber 在 readOnly 或 disabled 状态下忽略步进操作,不再触发 onStep。raw_summary 显示 src/InputNumber.tsx 的步进处理在只读或禁用状态下提前返回,tests/props.test.tsx 新增了对应的参数化测试。标题与变更内容一致,无需修改。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

小兔看见数字框,
只读禁用不跳跃。
按钮键盘都安静,
步进回调未响起。
测试轻轻点点头。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c967bf69-ac0b-4a10-a3c7-1f5d4570632b
Commits

Reviewing files that changed from the base of the PR and between 868bd31 and 9768068.

Files selected for processing: 2

  • src/InputNumber.tsx
  • tests/props.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@mokshupadhyay

Copy link
Copy Markdown
Contributor Author

Hi @zombieJ, the CI workflows on this PR are waiting for approval to run (first contribution to this repo). Could you approve them when you have a moment, and take a look at the change? Happy to adjust anything. Thanks!

@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.16%. Comparing base (868bd31) to head (9768068).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #764   +/-   ##
=======================================
  Coverage   96.16%   96.16%           
=======================================
  Files           6        6           
  Lines         365      365           
  Branches      103      104    +1     
=======================================
  Hits          351      351           
  Misses         14       14           

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

@yoyo837
yoyo837 merged commit 2af2f5c into react-component:master Dec 2, 2026
11 of 12 checks passed
ffgenius pushed a commit to antdv-next/vue-components that referenced this pull request Dec 3, 2026
* fix(input-number): do not trigger onStep when readOnly or disabled (react-component/input-number#764)

* chore(sync): advance color-picker, input-number, notification cursor to cd0412adc7, 2af2f5cd4f, 8e4f4226d0

---------

Co-authored-by: yanyubot <356405855+yanyubot@users.noreply.github.com>
@QDyanbing QDyanbing mentioned this pull request Dec 3, 2026
2 of 17 tasks
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