Skip to content

Commit

Permalink
Plans: scroll to the top when moving between pages (#45933)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcanepa authored Sep 28, 2020
1 parent fb98c8e commit 4d984bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion client/my-sites/plans-v2/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useTranslate } from 'i18n-calypso';
import page from 'page';
import React from 'react';
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

/**
Expand Down Expand Up @@ -60,6 +60,10 @@ const DetailsPage = ( {
const translate = useTranslate();
const isLoading = useIsLoading( siteId );

useEffect( () => {
window.scrollTo( 0, 0 );
}, [] );

// If the product slug isn't one that has options, proceed to the upsell.
if ( ! ( PRODUCTS_WITH_OPTIONS as readonly string[] ).includes( productSlug ) ) {
page.redirect( getPathToUpsell( rootUrl, productSlug, duration as Duration, siteSlug ) );
Expand Down
6 changes: 5 additions & 1 deletion client/my-sites/plans-v2/upsell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import page from 'page';
import { useTranslate } from 'i18n-calypso';
import React, { ReactNode, useCallback, useMemo } from 'react';
import React, { ReactNode, useCallback, useEffect, useMemo } from 'react';
import { useSelector } from 'react-redux';

/**
Expand Down Expand Up @@ -87,6 +87,10 @@ const UpsellComponent = ( {
[ upsellSlug ]
);

useEffect( () => {
window.scrollTo( 0, 0 );
}, [] );

return (
<Main className="upsell" wideLayout>
{ header }
Expand Down

0 comments on commit 4d984bd

Please sign in to comment.