Skip to content

Commit

Permalink
Merge pull request #170 from seasonedcc/fix-prevent-scroll-reset
Browse files Browse the repository at this point in the history
Fix: Pass preventScrollReset to submit function
  • Loading branch information
danielweinmann authored Mar 17, 2023
2 parents fc43e8b + 7988dd0 commit 12c0479
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/remix-forms/src/createForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,17 @@ type OnTransition<Schema extends SomeZodObject> = (
helpers: UseFormReturn<z.infer<Schema>, any>,
) => void

type SubmitFunction = ({ target }: { target: any }) => void
type LegacySubmitFunction = (event: { target: any }) => void

type SubmitFunction = (
event: { target: any },
options?: { preventScrollReset?: boolean },
) => void

type FetcherWithComponents = Transition & {
data: any
Form: FormComponent
submit: SubmitFunction
submit: SubmitFunction | LegacySubmitFunction
}

type FormProps<Schema extends FormSchema> = ComponentMappings & {
Expand Down Expand Up @@ -166,7 +171,7 @@ function createForm({
}: {
component: FormComponent
useNavigation: () => Transition
useSubmit: () => SubmitFunction
useSubmit: (() => SubmitFunction) | (() => LegacySubmitFunction)
useActionData: () => unknown
}) {
return function Form<Schema extends FormSchema>({
Expand Down Expand Up @@ -257,7 +262,9 @@ function createForm({
const { errors: formErrors, isValid } = formState

const onSubmit = (event: any) => {
form.handleSubmit(() => submit(event.target))(event)
form.handleSubmit(() =>
submit(event.target, { preventScrollReset: props.preventScrollReset }),
)(event)
}

const formRef = React.useRef<HTMLFormElement>(null)
Expand Down

0 comments on commit 12c0479

Please sign in to comment.