Skip to content

feat(Number Field): add startingValue prop for increment/decrement - #2628

Merged
zernonia merged 5 commits into
unovue:v2from
rikzwarthoff:v2_numberfield_startingvalue
Oct 1, 2026
Merged

zernonia merged 5 commits into
unovue:v2from
rikzwarthoff:v2_numberfield_startingvalue

Conversation

@rikzwarthoff

@rikzwarthoff rikzwarthoff commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

(#2627)

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Added new prop 'startingValue' to Number Field
When no value is present and startingValue is given, increment/decrement will fill the startingValue. If startingValue is not present it will fallback to previous behavior, min value or zero.

See the issue for an useful example.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • New Features

    • Number fields support an optional starting value. When the field is empty, its first increment or decrement uses that value, clamped to the configured minimum and maximum. The starting value is not snapped to the step; subsequent interactions follow the normal step behavior. If unset, the field starts from the minimum, or 0 when no minimum is configured.
  • Documentation

    • Added guidance and an example for configuring a number field’s starting value.

@coderabbitai

coderabbitai Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
CLAUDE.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: unovue/reka-ui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 517c500d-eaab-4772-b461-b6c0f049d398

📥 Commits

Reviewing files that changed from the base of the PR and between aeec578 and fab283c.

📒 Files selected for processing (4)
  • docs/content/docs/components/number-field.md
  • docs/content/meta/NumberFieldRoot.md
  • packages/core/src/NumberField/NumberField.test.ts
  • packages/core/src/NumberField/NumberFieldRoot.vue

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


📝 Walkthrough

Walkthrough

Adds an optional startingValue prop to Number Field. When an increment or decrement is requested from an empty input, the component uses this value, clamped to min and max without step snapping. If unset, it uses min or 0. Tests and documentation cover these behaviors.

Changes

Number Field Starting Value

Layer / File(s) Summary
Starting value behavior
packages/core/src/NumberField/NumberFieldRoot.vue, packages/core/src/NumberField/NumberField.test.ts, docs/content/docs/components/number-field.md, docs/content/meta/NumberFieldRoot.md
Adds and applies the optional startingValue prop when the input is empty. The value is clamped to min and max but is not snapped to step. Tests cover clamping, the default fallback, and subsequent step navigation. Documentation describes the prop and its behavior.

Priority: ⬇️ Low

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

Change: Feature

Suggested reviewers: xerox0213

Merge Risk: ⚪ Minimal · up to fab28

The starting-value behavior and its documented bounds are covered by tests for first use, subsequent steps, and the fallback when the prop is omitted. No material merge-readiness issue remains.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to fab28

The change remains confined to numeric UI state. The new starting value follows the existing model and form-output paths, retains bounds enforcement and disabled/read-only guards, and introduces no identified material security risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly affected exposure is a consuming application's Number Field instance, its model updates, and its named form value. The inspected new path introduces no tenant identity, credential, service authority, or privileged resource access.

Trust Boundaries and Controls

  • inferred — The caller-supplied prop changes which numeric value reaches an existing output path, rather than adding a new trust transition. Root interaction guards and bounds normalization remain on that path. These are UI controls, not evidence of downstream authorization or server-side validation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding the startingValue prop to control Number Field increment and decrement behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/core/src/NumberField/NumberField.test.ts (1)

94-108: ⚡ Quick win

Add edge-case coverage for startingValue outside [min, max] bounds.

The new test only covers the happy path (no min/max). A test with startingValue outside the configured range would expose the missing clampInputValue() call flagged above, and document the expected clamping behavior going forward.

✅ Suggested additional test
it('should clamp startingValue to min/max on first increment/decrement', async () => {
  // startingValue below min — first increment should clamp to min
  const { input, increment } = setup({ min: 10, max: 20, step: 3, startingValue: 5 })
  expect(input.value).toBe('')
  await userEvent.click(increment)
  expect(input.value).toBe('10') // clamped to min, snapped to step
})
🤖 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/core/src/NumberField/NumberField.test.ts` around lines 94 - 108, Add
a test to cover startingValue outside min/max so startingValue is clamped before
the first increment/decrement: update NumberField.test.ts to add a case using
setup({ min, max, step, startingValue }) (e.g., startingValue < min and
startingValue > max) and assert that after the first userEvent.click(increment)
or click(decrement) the input.value equals the clamped/snapped value; reference
the same setup helper and ensure behavior matches clampInputValue() (i.e.,
snapped to step and bounded by min/max) for both increment and decrement flows.
🤖 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.

Inline comments:
In `@packages/core/src/NumberField/NumberFieldRoot.vue`:
- Line 124: The NaN-branch assigns startingValue directly to modelValue.value
without enforcing bounds or step alignment; replace that direct assignment by
passing startingValue through the existing clampInputValue() logic (the same
function used elsewhere) before setting modelValue.value so the initial value is
clamped/snapped to [min, max] and step rules; update the assignment at
modelValue.value = startingValue.value ?? min.value ?? 0 to call
clampInputValue(startingValue.value) (or equivalent) and preserve the fallback
to min.value ?? 0 if startingValue is undefined/NaN.

---

Nitpick comments:
In `@packages/core/src/NumberField/NumberField.test.ts`:
- Around line 94-108: Add a test to cover startingValue outside min/max so
startingValue is clamped before the first increment/decrement: update
NumberField.test.ts to add a case using setup({ min, max, step, startingValue })
(e.g., startingValue < min and startingValue > max) and assert that after the
first userEvent.click(increment) or click(decrement) the input.value equals the
clamped/snapped value; reference the same setup helper and ensure behavior
matches clampInputValue() (i.e., snapped to step and bounded by min/max) for
both increment and decrement flows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd647a25-99a9-41ca-9f45-50285f34877d

📥 Commits

Reviewing files that changed from the base of the PR and between edbeb93 and a8944c5.

📒 Files selected for processing (2)
  • packages/core/src/NumberField/NumberField.test.ts
  • packages/core/src/NumberField/NumberFieldRoot.vue

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@packages/core/src/NumberField/NumberFieldRoot.vue`:
- Around line 123-125: The code clamps the parsed NaN input by calling
clampInputValue(startingValue.value ?? min.value ?? 0), but snapValueToStep
currently treats an undefined lower bound as 0 which causes a startingValue
(e.g., 40 with step 3) to snap down to 39; update clamp behavior so that when
startingValue is explicitly provided and min is undefined you preserve the raw
startingValue (do not call snapValueToStep against an implied 0), i.e., change
the logic around clampInputValue / snapValueToStep invocation to only snap to
step when a concrete lower bound (min) exists or when startingValue is absent,
referencing clampInputValue and snapValueToStep in NumberFieldRoot.vue and the
startingValue/min variables.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4edcc05f-b072-4ffb-8d9c-de579a98b15d

📥 Commits

Reviewing files that changed from the base of the PR and between a8944c5 and da1e58a.

📒 Files selected for processing (1)
  • packages/core/src/NumberField/NumberFieldRoot.vue

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/core/src/NumberField/NumberFieldRoot.vue (1)

123-125: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

clampInputValue snaps startingValue away from the intended value when min is undefined.

clampInputValue delegates to snapValueToStep(val, min, max, step). When min is undefined, snapValueToStep anchors the grid at 0. With the test's own configuration (startingValue: 40, step: 3, no min):

(40 − 0) % 3 = 1  →  snaps down to 39

The first increment will write 39 instead of the expected 40, and subsequent assertions (43, 40, 37) are all offset by −1, so the entire test will fail.

Semantically, startingValue represents an exact starting point, not a point that must align with the step grid. Only min/max clamping should apply here.

🛡️ Proposed fix
-    modelValue.value = startingValue.value !== undefined ? clampInputValue(startingValue.value) : min.value ?? 0
+    modelValue.value = startingValue.value !== undefined ? clamp(startingValue.value, min.value, max.value) : min.value ?? 0

clamp (already imported) enforces [min, max] bounds without snapping to the step grid, preserving the user's exact startingValue. Subsequent increments/decrements from that value will still be step-aligned.

🤖 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/core/src/NumberField/NumberFieldRoot.vue` around lines 123 - 125,
The code uses clampInputValue (which snaps via snapValueToStep) when
initializing modelValue from startingValue causing unwanted step snapping;
instead, preserve the exact startingValue and only enforce min/max bounds using
the existing clamp helper. Replace the clampInputValue call in the isNaN branch
with a clamp of startingValue.value against min and max (use min.value and
max.value or their undefined-aware defaults) so startingValue is not snapped to
the step grid while still respecting bounds; keep all other logic (modelValue,
startingValue, snapValueToStep) unchanged.
🤖 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.

Duplicate comments:
In `@packages/core/src/NumberField/NumberFieldRoot.vue`:
- Around line 123-125: The code uses clampInputValue (which snaps via
snapValueToStep) when initializing modelValue from startingValue causing
unwanted step snapping; instead, preserve the exact startingValue and only
enforce min/max bounds using the existing clamp helper. Replace the
clampInputValue call in the isNaN branch with a clamp of startingValue.value
against min and max (use min.value and max.value or their undefined-aware
defaults) so startingValue is not snapped to the step grid while still
respecting bounds; keep all other logic (modelValue, startingValue,
snapValueToStep) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8175c21f-13b2-4b92-94e3-05ec7453ea66

📥 Commits

Reviewing files that changed from the base of the PR and between da1e58a and aeec578.

📒 Files selected for processing (1)
  • packages/core/src/NumberField/NumberFieldRoot.vue

@zernonia

Copy link
Copy Markdown
Member

The new test passes only because the test harness accidentally disables step-snapping — so it isn't actually validating the increment/decrement behavior under real defaults.

The story component used by the tests (story/_NumberField.vue) uses a bare defineProps<NumberFieldRootProps>() without withDefaults, so stepSnapping arrives as undefined and resolves falsy inside clampInputValue. With snapping effectively off, clampInputValue(40) returns 40.

But the component's real default is stepSnapping: true. Under that default, clampInputValue(40) with step: 3 snaps to the nearest step and returns 39, not 40. I confirmed this locally — forcing stepSnapping: true makes the test fail:

AssertionError: expected '39' to be '40'

So as written, startingValue is silently altered by step-snapping and the test doesn't catch it.

Could we add an explicit case that pins this down, e.g.:

it('should snap startingValue to the nearest step when stepSnapping is on', async () => {
  const { input, increment } = setup({ step: 3, startingValue: 40, stepSnapping: true })
  await userEvent.click(increment)
  expect(input.value).toBe(/* whatever the intended behavior is */)
})

This forces a decision on the intended behavior:

  • if startingValue should be used verbatim, clamp to min/max but skip the step-snap (and update the test to expect 40);
  • if snapping is intended, document it on the prop and assert 39.

Either way the test should run with stepSnapping: true so it exercises the default code path.

@zernonia zernonia added the stale No activity for a long time label Sep 23, 2026
zernonia and others added 2 commits October 1, 2026 12:05
…o step

startingValue went through clampInputValue, which also snaps to the step grid, so with the
default stepSnapping a starting value of 40 and step 3 produced 39. Clamp it to min/max only.

The test passed because the story wrapper turns an absent stepSnapping into false. The tests
now set stepSnapping explicitly and cover clamping and the min fallback.

Also document the prop and regenerate the API meta.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2628

commit: fab283c

@zernonia
zernonia merged commit e923014 into unovue:v2 Oct 1, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No activity for a long time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants