Skip to content

Allow withForm components to accept extending properties #1334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 22 additions & 11 deletions packages/react-form/src/createFormHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,31 @@ export interface WithFormProps<
> {
// Optional, but adds props to the `render` function outside of `form`
props?: TRenderProps
render: (
render: <
TFFormData extends TFormData,
TFOnMount extends undefined | FormValidateOrFn<TFFormData>,
TFOnChange extends undefined | FormValidateOrFn<TFFormData>,
TFOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
TFOnBlur extends undefined | FormValidateOrFn<TFFormData>,
TFOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
TFOnSubmit extends undefined | FormValidateOrFn<TFFormData>,
TFOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFFormData>,
TFOnServer extends undefined | FormAsyncValidateOrFn<TFFormData>,
TFSubmitMeta,
>(
props: PropsWithChildren<
NoInfer<TRenderProps> & {
form: AppFieldExtendedReactFormApi<
TFormData,
TOnMount,
TOnChange,
TOnChangeAsync,
TOnBlur,
TOnBlurAsync,
TOnSubmit,
TOnSubmitAsync,
TOnServer,
TSubmitMeta,
TFFormData,
TFOnMount,
TFOnChange,
TFOnChangeAsync,
TFOnBlur,
TFOnBlurAsync,
TFOnSubmit,
TFOnSubmitAsync,
TFOnServer,
TFSubmitMeta,
TFieldComponents,
TFormComponents
>
Expand Down
17 changes: 14 additions & 3 deletions packages/react-form/tests/createFormHook.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ describe('createFormHook', () => {
const incorrectFormOpts = formOptions({
defaultValues: {
firstName: 'FirstName',
lastName: 'LastName',
firstNameWrong: 'FirstName',
lastNameWrong: 'LastName',
},
})

Expand All @@ -247,5 +244,19 @@ describe('createFormHook', () => {
// @ts-expect-error Incorrect form opts
<WithFormComponent form={incorrectAppForm} prop1="test" prop2={10} />
)

const extendingFormOpts = formOptions({
defaultValues: {
firstName: 'FirstName',
lastName: 'LastName',
country: 'Country',
},
})

const extendingAppForm = useAppForm(extendingFormOpts)

const ExtendingFormOptsComponent = (
<WithFormComponent form={extendingAppForm} prop1="test" prop2={10} />
)
})
})