Repository navigation
fix(input)!: keep counter stepping in sync with the current value - #3266
Merged
interactivellama merged 2 commits intoNov 2, 2026
Merged
Conversation
Holding a counter button repeats performStep from a timer. The timer called the performStep closure from the render where the button was pressed, so in controlled mode it kept reading the old value prop and reported the same number on every repeat. Call the latest performStep through a ref instead, as the pre-rewrite class did by reading this.props.value on each step. In uncontrolled mode a step writes the new value straight to the input element and nothing re-rendered, so the increment and decrement buttons kept their old disabled state after reaching maxValue or minValue. Re-render after the write, matching the forceUpdate call in the pre-rewrite class. Add regression tests for both cases.
Contributor
|
Videos match the bug, but the description does not. I believe the bugs being solved are:
|
interactivellama
approved these changes
Nov 2, 2026
Contributor
Author
|
Thanks for the review and merge. This behaviour was a stale closure repeating the first stepped value I'll be more careful to match the description to the observed behaviour next time. |
Niznikr
added a commit
that referenced
this pull request
Nov 4, 2026
Conflicts came from #3268 (forwardRef, className on the root), #3266 (Input counter), #3270 (Carousel autoplay) and #3265 (MenuDropdown open registration). - Slider, VerticalNavigation, Popover, Tree: keep master's forwardRef, root className and classNameList/styleList, with the controlled value and selection from this branch. - Input, Carousel, MenuDropdown: keep this branch's implementation, which already fixes the same stale closures through refs. Master's regression tests are kept; the uncontrolled Input maxValue test is rewritten for a controlled counter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additional description
Fixes two bugs in the
Inputcounter variant (variant="counter"), both regressions from the function-component rewrite:maxValueorminValue. Before, they stayed enabled.No props, types or exports change.
Motivation
Controlled: with a controlled
value, holding the increment button calledonChangewith the same number on every repeat (1, 1, 1, …). The input never got past the first step.Uncontrolled: with
defaultValue="0"andmaxValue={1}, clicking increment moved the input to1but left the increment button enabled. The same happened atminValuewith the decrement button.The pre-rewrite class avoided both. It read
this.props.valueon every step and calledforceUpdateafter writing to the input element.Root cause and fix
performStepschedules its own repeat withsetTimeout. That callback called theperformStepfrom the render where the button was pressed, and that closure captured thevalueprop from that render. Every repeat computed the next number from the original value.performStepis now stored inperformStepRefon each render, and the timer callsperformStepRef.current, so every repeat reads the current props.<input>element (inputElementRef.current.value = ...), and nothing triggered a render. The disabled state of the counter buttons is computed during render from that value, so it was never recomputed. The step now callsforceRender()(auseReducercounter) after the write.Test Plans
value. Hold the increment button for a few seconds. The value should keep rising andonChangeshould report a new number each time.defaultValue="0"andmaxValue={1}, click increment once, and confirm the increment button is disabled.Test Results
New regression tests in
components/input/__tests__/input.test.jsx:keeps counting while a button is held in controlled mode(fake timers; assertsonChangereports['1', '2', '3', '4'])disables the increment button at maxValue in uncontrolled mode[above text added by @interactivellama]
Screen Shots
before
2026-10-30.9.23.15.mov
after
2026-10-30.9.22.06.mov
CONTRIBUTOR checklist (do not remove)
Please complete for every pull request.
Green gate — all of these must pass locally (CI runs the same):
npm run lintpasses with 0 errors (npm run lint:fixto auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.npm run typecheckis clean (tsc --noEmit).npm test -- --runpasses — this runs both Vitest projects (jsdomunit+ real-browserbrowser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots withnpm test -- --run -uand review the diff.npm run buildsucceeds (type-check + Vite library build +.d.ts+ entry shims).Behavior & docs:
components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a*.browser.test.jsxfile (thebrowserproject); everything else is jsdom.npm run storybook→ http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).content/visualPickerFigure, render props likerenderItem,iconprops,events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check againstcomponents/<name>/__examples__..d.ts(they're generated by the build); JS consumers rely on them via editor type-acquisition.REVIEWER checklist (do not remove)
CIworkflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).@salesforce/design-system-react/components/<name>and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change →feat!:/BREAKING CHANGE:and a major version bump.