Skip to content

Fix #1082: pass ref through Field custom component path - #1097

Open
Steve0x2a wants to merge 1 commit into
final-form:mainfrom
Steve0x2a:fix/field-custom-component-ref
Open

Fix #1082: pass ref through Field custom component path#1097
Steve0x2a wants to merge 1 commit into
final-form:mainfrom
Steve0x2a:fix/field-custom-component-ref

Conversation

@Steve0x2a

@Steve0x2a Steve0x2a commented Aug 29, 2026

Copy link
Copy Markdown

Field is React.forwardRef. The string-component path already passes ref through React.createElement. The custom-component path dropped it in v7 (renderComponent({ children, component, ...rest, ...mergedField })).

Restore the pre-v7 pass-through so a custom component receives the forwarded ref.

Reported by @barettjfed.

Fixes #1082

Summary by CodeRabbit

  • Bug Fixes
    • Refs passed to fields now correctly reach custom components, including components created with React.forwardRef.
    • Improved access to the underlying input element when using custom field renderers.

Field is a forwardRef wrapper. The string-component branch already
forwards ref via createElement; the custom-component branch dropped it
in v7. Restore the pre-v7 pass-through so custom components receive the
ref.

Fixes final-form#1082
@Steve0x2a
Steve0x2a requested a review from erikras as a code owner August 29, 2026 21:37
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d3077161-240c-460a-9e70-1ce9d9513ca5

📥 Commits

Reviewing files that changed from the base of the PR and between e09c3cf and a3096b2.

📒 Files selected for processing (2)
  • src/Field.test.js
  • src/Field.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

FieldComponent now passes its forwarded ref to custom components through renderComponent. A test verifies that a custom React.forwardRef input receives an HTMLInputElement ref.

Changes

Field ref forwarding

Layer / File(s) Summary
Forward refs through custom components
src/Field.tsx, src/Field.test.js
FieldComponent includes the forwarded ref in renderComponent props. A test verifies ref access through a custom React.forwardRef input.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to a3096

This restores forwarded refs for custom Field components and is covered by a regression test; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: erikras

Poem

A rabbit checked the ref with care
It reached the input waiting there
Through custom fields the signal flew
The test confirmed the path was true
Carrots cheer the fix anew

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the ref propagation fix in the Field custom component path and references issue #1082.
Linked Issues check ✅ Passed The change passes the forwarded ref to renderComponent for custom components and adds a test that verifies ref forwarding to a React.forwardRef component. This satisfies the requirements in [#1082].
Out of Scope Changes check ✅ Passed The code change and regression test directly support ref propagation through the Field custom component path. No unrelated changes are present.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Ref broken on custom component

1 participant