Skip to content

Commit f05ab79

Browse files
committed
fix: Cross-platform FormSubmitEvent via Register
1 parent e1d7845 commit f05ab79

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/form-core/src/FormApi.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import type { DeepKeys, DeepValue, Updater } from './utils'
44
import { functionalUpdate, getBy, setBy } from './utils'
55
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi'
66

7+
export interface Register {
8+
// FormSubmitEvent
9+
}
10+
11+
export type FormSubmitEvent = Register extends {
12+
FormSubmitEvent: infer E
13+
}
14+
? E
15+
: Event
16+
717
export type FormOptions<TData> = {
818
defaultValues?: TData
919
defaultState?: Partial<FormState<TData>>
@@ -245,7 +255,7 @@ export class FormApi<TFormData> {
245255
return this.validationMeta.validationPromise
246256
}
247257

248-
handleSubmit = async (e: Event) => {
258+
handleSubmit = async (e: FormSubmitEvent) => {
249259
e.preventDefault()
250260
e.stopPropagation()
251261

packages/react-form/src/useForm.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { createUseField, type UseField } from './useField'
88
import { formContext } from './formContext'
99

1010
declare module '@tanstack/form-core' {
11+
interface Register {
12+
FormSubmitEvent: React.FormEvent<HTMLFormElement>
13+
}
14+
1115
// eslint-disable-next-line no-shadow
1216
interface FormApi<TFormData> {
1317
Form: FormComponent

0 commit comments

Comments
 (0)