Skip to content

Commit ce42986

Browse files
forivallerikras
authored andcommitted
Fix handleSubmit typings (#715)
1 parent 3450d7d commit ce42986

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/ReactFinalForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
FormValuesShape,
1414
Unsubscribe
1515
} from 'final-form'
16-
import type { FormProps as Props } from './types'
16+
import type { FormProps as Props, SubmitEvent } from './types'
1717
import renderComponent from './renderComponent'
1818
import useWhenValueChanges from './useWhenValueChanges'
1919
import useConstant from './useConstant'
@@ -163,7 +163,7 @@ function ReactFinalForm<FormValues: FormValuesShape>({
163163
form.setConfig('validateOnBlur', validateOnBlur)
164164
})
165165

166-
const handleSubmit = (event: ?SyntheticEvent<HTMLFormElement>) => {
166+
const handleSubmit = (event: ?SubmitEvent) => {
167167
if (event) {
168168
// sometimes not true, e.g. React Native
169169
if (typeof event.preventDefault === 'function') {

src/types.js.flow

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ export type FieldRenderProps = {
5151
}
5252
}
5353

54+
export type SubmitEvent = {
55+
preventDefault?: $PropertyType<SyntheticEvent<EventTarget>, 'preventDefault'>,
56+
stopPropagation?: $PropertyType<
57+
SyntheticEvent<EventTarget>,
58+
'stopPropagation'
59+
>
60+
}
61+
5462
export type FormRenderProps<FormValues: FormValuesShape> = {
55-
handleSubmit: (?SyntheticEvent<HTMLFormElement>) => ?Promise<?Object>,
63+
handleSubmit: (?SubmitEvent) => ?Promise<?Object>,
5664
form: FormApi<FormValues>
5765
} & FormState<FormValues>
5866

typescript/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export interface FormRenderProps<FormValues = AnyObject>
5353
RenderableProps<FormRenderProps<FormValues>> {
5454
form: FormApi<FormValues>;
5555
handleSubmit: (
56-
event?: React.SyntheticEvent<HTMLFormElement>
56+
event?: Partial<
57+
Pick<React.SyntheticEvent, 'preventDefault' | 'stopPropagation'>
58+
>
5759
) => Promise<AnyObject | undefined> | undefined;
5860
}
5961

0 commit comments

Comments
 (0)