Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plans: scroll to the top when moving across pages #45933

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -53,6 +53,10 @@ const DetailsPage = ( { duration, productSlug, rootUrl, header }: DetailsPagePro
const translate = useTranslate();
const isLoading = useIsLoading( siteId );

useEffect( () => {
window.scrollTo( 0, 0 );
}, [] );
Comment on lines +56 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reset the scroll just after the first render.


// 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 );
}, [] );
Comment on lines +90 to +92
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reset the scroll just after the first render.


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