@@ -15,11 +15,13 @@ export default function usePages({
1515 formElementsValidation,
1616 formElementsConditionallyShown,
1717 hasAttemptedSubmit,
18+ scrollToTopOfPage,
1819} : {
1920 pages : FormTypes . PageElement [ ]
2021 formElementsValidation : FormElementsValidation | undefined
2122 formElementsConditionallyShown : FormElementsConditionallyShown
2223 hasAttemptedSubmit : boolean
24+ scrollToTopOfPage ?: boolean
2325} ) {
2426 const scrollToTopOfPageHTMLElementRef = React . useRef < HTMLDivElement > ( null )
2527 const [ visitedPageIds , setVisitedPageIds ] = React . useState < string [ ] > ( [ ] )
@@ -80,31 +82,41 @@ export default function usePages({
8082 const scrollToTopOfPageHTMLElement =
8183 scrollToTopOfPageHTMLElementRef . current
8284 if ( isShowingMultiplePages && scrollToTopOfPageHTMLElement ) {
83- if ( scrollToTopOfPageHTMLElement ) {
85+ if ( scrollToTopOfPage ) {
8486 window . requestAnimationFrame ( ( ) => {
85- scrollToTopOfPageHTMLElement . scrollIntoView ( {
86- block : 'start' ,
87- behavior : 'smooth' ,
88- } )
87+ window . scrollTo ( { top : 0 , behavior : 'smooth' } )
8988 } )
90- }
91- const stepItemHTMLElement = document . getElementById (
92- `steps-navigation-step-${ pageId } ` ,
93- )
94- if ( stepItemHTMLElement ) {
89+ } else if ( scrollToTopOfPageHTMLElement ) {
9590 window . requestAnimationFrame ( ( ) => {
96- stepItemHTMLElement . scrollIntoView ( {
91+ scrollToTopOfPageHTMLElement . scrollIntoView ( {
9792 block : 'start' ,
9893 behavior : 'smooth' ,
9994 } )
10095 } )
96+ const stepItemHTMLElement = document . getElementById (
97+ `steps-navigation-step-${ pageId } ` ,
98+ )
99+ if ( stepItemHTMLElement ) {
100+ window . requestAnimationFrame ( ( ) => {
101+ stepItemHTMLElement . scrollIntoView ( {
102+ block : 'start' ,
103+ behavior : 'smooth' ,
104+ } )
105+ } )
106+ }
101107 }
108+
102109 //blur prev/next buttons after they've been clicked
103110 const activeElement = document ?. activeElement as HTMLElement
104111 activeElement . blur ( )
105112 }
106113 } ,
107- [ closeStepsNavigation , currentPageId , isShowingMultiplePages ] ,
114+ [
115+ closeStepsNavigation ,
116+ currentPageId ,
117+ isShowingMultiplePages ,
118+ scrollToTopOfPage ,
119+ ] ,
108120 )
109121
110122 const goToNextPage = React . useCallback ( ( ) => {
0 commit comments