From a3096b21099e68a164077274d3a795b3ecc8ed2d Mon Sep 17 00:00:00 2001 From: Yi Zhan Date: Sat, 29 Aug 2026 21:36:58 +0000 Subject: [PATCH] Pass ref through Field custom component path 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 #1082 --- src/Field.test.js | 19 +++++++++++++++++++ src/Field.tsx | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Field.test.js b/src/Field.test.js index fa3da45..ada6db5 100644 --- a/src/Field.test.js +++ b/src/Field.test.js @@ -426,6 +426,25 @@ describe("Field", () => { expect(ref.current instanceof HTMLInputElement).toBe(true); }); + it("should pass ref through to a custom component", () => { + const ref = React.createRef(); + const CustomInput = React.forwardRef(({ input }, innerRef) => ( + + )); + render( +
+ {() => ( + + + + )} + , + ); + + expect(ref.current).not.toBe(null); + expect(ref.current instanceof HTMLInputElement).toBe(true); + }); + it("should not pass an undefined type through to the input", () => { const MyInput = jest.fn(({ input }) => ); render( diff --git a/src/Field.tsx b/src/Field.tsx index d86f859..456aa6a 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -93,7 +93,7 @@ function FieldComponent< } return renderComponent( - { children, component, ...rest, ...mergedField }, + { children, component, ref, ...rest, ...mergedField }, {}, `Field(${name})`, );