Skip to content

Commit

Permalink
fix: Cross-platform FormSubmitEvent via Register
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed May 1, 2023
1 parent e1d7845 commit f05ab79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import type { DeepKeys, DeepValue, Updater } from './utils'
import { functionalUpdate, getBy, setBy } from './utils'
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi'

export interface Register {
// FormSubmitEvent
}

export type FormSubmitEvent = Register extends {
FormSubmitEvent: infer E
}
? E
: Event

export type FormOptions<TData> = {
defaultValues?: TData
defaultState?: Partial<FormState<TData>>
Expand Down Expand Up @@ -245,7 +255,7 @@ export class FormApi<TFormData> {
return this.validationMeta.validationPromise
}

handleSubmit = async (e: Event) => {
handleSubmit = async (e: FormSubmitEvent) => {
e.preventDefault()
e.stopPropagation()

Expand Down
4 changes: 4 additions & 0 deletions packages/react-form/src/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { createUseField, type UseField } from './useField'
import { formContext } from './formContext'

declare module '@tanstack/form-core' {
interface Register {
FormSubmitEvent: React.FormEvent<HTMLFormElement>
}

// eslint-disable-next-line no-shadow
interface FormApi<TFormData> {
Form: FormComponent
Expand Down

0 comments on commit f05ab79

Please sign in to comment.