fix(form): scroll+focus the first errored field on invalid submit (#2793)#2813
Merged
Conversation
) The missing-required-field toast (#2329) names the fields but leaves the user hunting — in a long form the offending field is off-screen and RHF's native focus-on-error silently no-ops for custom widgets (lookup / select / master-detail), the exact reported case. Disable RHF's unreliable shouldFocusError and, in onInvalid, scroll the first errored field (visual order) into view via its data-field wrapper and focus a focusable control inside it — works for every field type. Verified with an RTL DOM test that renders the real form renderer: submit with a missing required field toasts, scrolls, and focuses the first error; picks the first *errored* field when an earlier one is valid; stays quiet on a valid submit. Red-checked against the pre-fix code. Full form suite (15) and type-check pass. Browser verification was blocked by the shared checkout's mid-migration state; the DOM test covers the real render path. Closes #2793 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
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.
Closes #2793 — found during the framework internal-training dogfood.
What #2793 actually needed
The issue asked for two things on an invalid submit: a toast naming the missing fields, and scroll/focus to the first errored field.
Verifying at the code level first (the lesson from #3419): the toast half already shipped in #2329 (2026-07-06, before the 07-23 dogfood observation). The original "no toast" was almost certainly the framework showcase's stale bundled console (a prebuilt objectui artifact that lagged main), not a live bug.
The scroll/focus half was genuinely still missing — no
scrollIntoView/setFocus/shouldFocusErroranywhere. react-hook-form's native focus-on-error only reaches fields whose registered ref is a focusable native input; it silently no-ops for custom widgets (lookup / select / master-detail), which is exactly the reported field.The fix
shouldFocusError(it no-ops for custom widgets and would fight our explicit handler).onInvalidhandler, after the existing toast, scroll the first errored field in visual/declared order (not RHF's error-key order) into view via itsdata-fieldwrapper, and focus a focusable control inside it. Works for every field type; scoped to this form via a ref so it never reaches a sibling form.Verification
plugin-form/componentsform-renderer suite (15) andtype-checkpass — no regression from theshouldFocusErrorchange.externalIdmigration left it mid-flight —externalId: expected string, received array). The DOM test renders the actual component to compensate; I did not touch the shared checkout.Note
This closes #2793 by delivering its remaining half; the toast half pre-existed (#2329).
🤖 Generated with Claude Code