@@ -593,6 +593,12 @@ export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
593
593
*/
594
594
relative ?: RelativeRoutingType ;
595
595
596
+ /**
597
+ * Prevent the scroll position from resetting to the top of the viewport on
598
+ * completion of the navigation when using the <ScrollRestoration> component
599
+ */
600
+ preventScrollReset ?: boolean ;
601
+
596
602
/**
597
603
* A function to call when the form is submitted. If you call
598
604
* `event.preventDefault()` then this form will not do anything.
@@ -640,6 +646,7 @@ const FormImpl = React.forwardRef<HTMLFormElement, FormImplProps>(
640
646
fetcherKey,
641
647
routeId,
642
648
relative,
649
+ preventScrollReset,
643
650
...props
644
651
} ,
645
652
forwardedRef
@@ -664,6 +671,7 @@ const FormImpl = React.forwardRef<HTMLFormElement, FormImplProps>(
664
671
method : submitMethod ,
665
672
replace,
666
673
relative,
674
+ preventScrollReset,
667
675
} ) ;
668
676
} ;
669
677
@@ -906,6 +914,7 @@ function useSubmitImpl(fetcherKey?: string, routeId?: string): SubmitFunction {
906
914
let href = url . pathname + url . search ;
907
915
let opts = {
908
916
replace : options . replace ,
917
+ preventScrollReset : options . preventScrollReset ,
909
918
formData,
910
919
formMethod : method as FormMethod ,
911
920
formEncType : encType as FormEncType ,
@@ -1000,8 +1009,9 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
1000
1009
Form : ReturnType < typeof createFetcherForm > ;
1001
1010
submit : (
1002
1011
target : SubmitTarget ,
1003
- // Fetchers cannot replace because they are not navigation events
1004
- options ?: Omit < SubmitOptions , "replace" >
1012
+ // Fetchers cannot replace/preventScrollReset because they are not
1013
+ // navigation events
1014
+ options ?: Omit < SubmitOptions , "replace" | "preventScrollReset" >
1005
1015
) => void ;
1006
1016
load : ( href : string ) => void ;
1007
1017
} ;
@@ -1165,7 +1175,7 @@ function useScrollRestoration({
1165
1175
}
1166
1176
}
1167
1177
1168
- // Opt out of scroll reset if this link requested it
1178
+ // Don't reset if this navigation opted out
1169
1179
if ( preventScrollReset === true ) {
1170
1180
return ;
1171
1181
}
0 commit comments