fix: Cross-platform FormSubmitEvent via Register

This commit is contained in:
Tanner Linsley
2023-05-01 11:58:55 -06:00
parent e1d7845721
commit f05ab79ef6
2 changed files with 15 additions and 1 deletions

View File

@@ -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>>
@@ -245,7 +255,7 @@ export class FormApi<TFormData> {
return this.validationMeta.validationPromise
}
handleSubmit = async (e: Event) => {
handleSubmit = async (e: FormSubmitEvent) => {
e.preventDefault()
e.stopPropagation()

View File

@@ -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