Repository navigation
fix(Form): check every name in isFieldInvalid; guard and focus scrollToFirstError - #61
Merged
Merged
Conversation
hugomallet
commented
Aug 6, 2026
hugomallet
left a comment
Collaborator
Author
There was a problem hiding this comment.
Code review (tooled self-review)
Disclosure: PR authored under my own account, so GitHub won't accept an APPROVE — this is a tooled self-review posted as a comment. Review ran on a clean worktree: ESLint + tsc --noEmit clean, full suite green (6 suites, 66 tests, 5 snapshots).
Verdict: mergeable — minor comments only, none blocking.
Verified
isFieldInvalidmulti-name: passingnamesstraight togetFieldErrorsyields the union offilterByFieldNameWithWildcardper name — correct OR semantics, wildcards (user.*) preserved.- Guard: on the submit path
errors[0]is always defined (handleSubmitErroronly runs whenvalidis false; AJV guarantees non-emptyerrorsthen, andformatErrorsmaps 1:1 without filtering). - Focus: a non-focusable element carrying
name(e.g. a div) makesfocus()a harmless no-op;preventScrollcorrectly avoids fighting the 900ms animated scroll. - Scope: strictly
Form.js+Form.test.js, no snapshot change needed — confirmed by the full run.
Minor (grouped, take or leave)
scrollToFirstErrordirect call (Form.js:343): a consumer calling it via instance ref on a valid form hitsfirstError.field→ TypeError. One-line hardening:if (!firstError) return;above the DOM lookup.preventScrollon old Safari (< 15, still within>0.2%browserslist): the option is ignored, so focus triggers an instant scroll competing with the animation. Graceful degradation — fine as is; focusing after the scroll duration would fix it if it ever matters.- Focus test cleanup (
Form.test.js):wrapper.detach()/removeChildrun after the assertion, so a failing expect leaks the attached container into later tests.try/finally(orafterEach) would make it robust. - Micro:
isFieldInvalidnormalizesfieldNamesintonames, thengetFieldErrorsre-normalizes — the local array could be dropped.
Aside (pre-existing, out of scope)
The should match snapshot test fails when the suite runs alone (--testPathPattern Form/Form.test.js): the snapshot serializes the AJV instance, which embeds jest's console (BufferedConsole vs CustomConsole depending on worker mode). Not caused by this PR — worth a follow-up to stop snapshotting the AJV instance.
hugomallet
added a commit
that referenced
this pull request
Aug 6, 2026
- scrollToFirstError: return early when the form has no errors, so a direct call through a ref on a valid form no longer throws. - isFieldInvalid: drop the redundant array normalization, already done by getFieldErrors. - focus test: cleanup (detach + remove container) moved to a finally block so a failing assertion no longer leaks the attached container.
…ToFirstError
- isFieldInvalid([a, b]) now checks every name instead of only the
first: pass the array straight to getFieldErrors, which already
accepts one.
- scrollToFirstError no longer forwards undefined to scrollToElement
when no DOM element carries the first error's name (custom field,
required error on a nested object).
- After scrolling, focus moves to the first invalid field
(element.focus({ preventScroll: true })) for keyboard users (#57).
- scrollToFirstError: return early when the form has no errors, so a direct call through a ref on a valid form no longer throws. - isFieldInvalid: drop the redundant array normalization, already done by getFieldErrors. - focus test: cleanup (detach + remove container) moved to a finally block so a failing assertion no longer leaks the attached container.
hugomallet
force-pushed
the
fix/form-invalid-scroll
branch
from
August 6, 2026 13:13
9713a19 to
89b555e
Compare
This was referenced Aug 6, 2026
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.
Fixes
isFieldInvalid(['a', 'b'])only checked the first name (getFieldErrors(...tuple)dropped the rest). Now passes the array directly —getFieldErrorsalready accepts one.undefinedwas forwarded toscrollToElement. Now returns early.element.focus({ preventScroll: true }).Tests
3 new tests, each verified to fail against the un-fixed code:
isFieldInvalidwith the error on the second name onlydocument.activeElementis the invalid fieldCI=true yarn test:runtime: 6 suites, 66 tests (63 on master), 5 snapshots — all green.