Clamp NumberInput numeric values#1978
Conversation
📝 WalkthroughWalkthroughFixes NumberInput so typed values are clamped to the configured min/max range via the numericValue getter, matching existing arrow-key clamping behavior. Test file updated with explicit event callback stubs and a new test validating clamped numericValue, onChange, and onSubmit behavior. ChangesTyped Value Clamping Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Hi @Tomeshwari-02 👋 ⭐ Star this repo before your PR merges. Why? GSSoC 2026 contributors who star get priority review and points credit. After you star, push any commit (or re-run this check). The Thanks for your contribution to TermUI. |
There was a problem hiding this comment.
🎉 Thanks for your first PR to TermUI, @Tomeshwari-02.
Before your PR merges:
- ⭐ Star the repo. Required. The
star-checkjob blocks your merge otherwise. - ✅ All checks green:
build,test,typecheck. - 🏷 PR title follows
type: short description. Example:fix: handle empty list. - 🔗 Link your closing issue in the description.
GSSoC 2026 points come from labels after merge:
gssoc:approved. +50 base points.level:beginner/intermediate/advanced/critical. +20 / +35 / +55 / +80.quality:clean/exceptional. x 1.2 / x 1.5.type:*. Stackable bonus.
Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.
🚀 Welcome to the cohort.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/ui/src/NumberInput.test.ts (1)
70-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMissing test for typed value clamped below
min.Only the above-
maxtyped-clamp case is covered. The PR objectives explicitly call for coverage of values typed belowminclamping tomin, in addition to above-max. Consider adding a symmetric test.✅ Suggested additional test
it('clamps typed values exposed through numericValue and submit', () => { const onChange = vi.fn(); const onSubmit = vi.fn(); const input = new NumberInput({}, { min: 0, max: 10, onChange, onSubmit }); input.insertChar('9'); input.insertChar('9'); input.submit(); expect(input.rawValue).toBe('99'); expect(input.numericValue).toBe(10); expect(onChange).toHaveBeenLastCalledWith(10); expect(onSubmit).toHaveBeenCalledWith(10); }); + + it('clamps typed values below min exposed through numericValue and submit', () => { + const onChange = vi.fn(); + const onSubmit = vi.fn(); + const input = new NumberInput({}, { min: 5, max: 10, onChange, onSubmit }); + + input.insertChar('2'); + input.submit(); + + expect(input.rawValue).toBe('2'); + expect(input.numericValue).toBe(5); + expect(onChange).toHaveBeenLastCalledWith(5); + expect(onSubmit).toHaveBeenCalledWith(5); + });🤖 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 `@packages/ui/src/NumberInput.test.ts` around lines 70 - 84, Add a symmetric NumberInput test covering typed values clamped below min: in NumberInput.test.ts, create a case using NumberInput with min/max plus onChange/onSubmit, type a value below min via insertChar, call submit, and assert rawValue stays typed while numericValue, onChange, and onSubmit all reflect the clamped min. Reuse the existing clamping pattern around NumberInput.numericValue and NumberInput.submit so the suite covers both below-min and above-max typed input.
🤖 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 `@packages/ui/src/NumberInput.test.ts`:
- Around line 70-84: Add a symmetric NumberInput test covering typed values
clamped below min: in NumberInput.test.ts, create a case using NumberInput with
min/max plus onChange/onSubmit, type a value below min via insertChar, call
submit, and assert rawValue stays typed while numericValue, onChange, and
onSubmit all reflect the clamped min. Reuse the existing clamping pattern around
NumberInput.numericValue and NumberInput.submit so the suite covers both
below-min and above-max typed input.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 70faff52-59d3-4c4d-8a66-cde7ec69871b
📒 Files selected for processing (2)
packages/ui/src/NumberInput.test.tspackages/ui/src/NumberInput.ts
Summary
Fixes #1968
Testing
Summary by CodeRabbit