Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<input {...input} ref={innerRef} />
));
render(
<Form onSubmit={onSubmitMock} subscription={{ values: true }}>
{() => (
<form>
<Field name="name" component={CustomInput} ref={ref} />
</form>
)}
</Form>,
);

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 }) => <input {...input} />);
render(
Expand Down
2 changes: 1 addition & 1 deletion src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function FieldComponent<
}

return renderComponent(
{ children, component, ...rest, ...mergedField },
{ children, component, ref, ...rest, ...mergedField },
{},
`Field(${name})`,
);
Expand Down