Skip to content

Fix FieldArray active and touched meta#201

Open
erikras-richard-agent wants to merge 1 commit into
masterfrom
fix-fieldarray-meta-active-touched-175
Open

Fix FieldArray active and touched meta#201
erikras-richard-agent wants to merge 1 commit into
masterfrom
fix-fieldarray-meta-active-touched-175

Conversation

@erikras-richard-agent
Copy link
Copy Markdown
Contributor

@erikras-richard-agent erikras-richard-agent commented May 7, 2026

Summary

  • aggregate subscribed FieldArray meta.active from the currently active child field
  • aggregate subscribed FieldArray meta.touched from touched child fields
  • keep the optimized default subscription intact and add regression coverage for the explicit active/touched subscription path

Closes #175

Test Plan

  • yarn nps typescript
  • yarn test
  • yarn nps lint

Summary by CodeRabbit

  • Improvements

    • FieldArray components now correctly expose meta.active and meta.touched states when subscribed, providing accurate tracking of field focus and interaction status.
  • Tests

    • Added test coverage for FieldArray meta state behavior with focus and blur interactions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a0fd8a15-990e-451f-9e5b-4e4835f255a7

📥 Commits

Reviewing files that changed from the base of the PR and between abe54d9 and 3280c9c.

📒 Files selected for processing (2)
  • src/FieldArray.test.tsx
  • src/useFieldArray.ts

📝 Walkthrough

Walkthrough

The PR fixes meta.active and meta.touched being undefined for FieldArray by conditionally computing them as aggregate properties of child fields only when requested via subscription options. A new test verifies the behavior works correctly on focus and blur events.

Changes

FieldArray Meta Aggregation

Layer / File(s) Summary
Helper & Imports
src/useFieldArray.ts
Adds useFormState import and isArrayField helper to identify fields belonging to the array; introduces explicit defaultSubscription for { length, value, error }.
Subscription Logic
src/useFieldArray.ts
Uses useFormState with computed subscription for active and/or touched based on caller-provided options; extracts field state and builds metaWithoutLength by copying meta descriptors while excluding length.
Conditional Meta Getters
src/useFieldArray.ts
Conditionally defines enumerable lazy getters for active and touched on metaWithoutLength, computing them from formState and checking whether the array has active/touched descendant fields via isArrayField.
Tests & Verification
src/FieldArray.test.tsx
Adds test case verifying that meta.active and meta.touched aggregate correctly when subscribed to; asserts initial state, then validates state changes on focus and blur of array inputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • erikras

Poem

🐰 The array's feelings, long kept still,
Now shine when asked with subscription's will,
Active and touched from children below,
Aggregate up with a lazy getter's glow,
FieldArray's heart beats true at last!

🚥 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 summarizes the main change: fixing FieldArray's meta.active and meta.touched properties, which directly addresses the core issue.
Linked Issues check ✅ Passed The PR implements both required behaviors from issue #175: aggregating meta.active when any child field is active, and aggregating meta.touched when any child field has been touched.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the fix for meta.active and meta.touched aggregation; no unrelated modifications detected in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-fieldarray-meta-active-touched-175

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 and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Meta.active and meta.touched always undefined?

1 participant