fix(SimpleFormIterator): add disableAutoFocus option when adding items #11101
+32
−2
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.
Problem
SimpleFormIterator always focuses the first input of a newly added item because it relies on react-hook-form’s useFieldArray.append, which auto-focuses by default.
This happens even when inputs explicitly do not request focus, making it impossible to opt out of this behavior (e.g. when adding multiple rows quickly or when focus management is handled elsewhere).
Solution
This PR introduces a new optional prop: disableAutoFocus on SimpleFormIterator.
When enabled, the iterator passes { shouldFocus: false } to react-hook-form’s append method, preventing automatic focus on newly added items.
Default behavior remains unchanged.
The change is fully opt-in.
Focus control is handled at the iterator level, which is the correct abstraction for this behavior.
How To Test
Run Storybook:
npx storybook devOpen the SimpleFormIterator stories
Open the story demonstrating disableAutoFocus
Click
AddCompare with the default story
Focus behavior can be verified visually or by inspecting document.activeElement in browser dev tools.
Additional Checks
nextfor a featureAlso, please make sure to read the contributing guidelines.