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})`, );