Skip to content

Commit

Permalink
Implement scroll restore and scroll to the top of the page on navigate
Browse files Browse the repository at this point in the history
Using ScrollRestoration (except for pagination)
  • Loading branch information
lukaw3d committed Jun 21, 2023
1 parent 49ecf54 commit e26a5e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/567.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement scroll restore and scroll to the top of the page on navigate
6 changes: 5 additions & 1 deletion src/app/components/LoadMoreButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export const LoadMoreButton: FC<LoadMoreButtonProps> = ({ isLoading, pagination
const { t } = useTranslation()

return (
<Link component={RouterLink} to={pagination.linkToPage(pagination.selectedPage + 1)}>
<Link
component={RouterLink}
to={pagination.linkToPage(pagination.selectedPage + 1)}
preventScrollReset={true}
>
<StyledLoadMoreButton color="primary" variant="contained" disabled={isLoading}>
{t('common.loadMore')}
</StyledLoadMoreButton>
Expand Down
1 change: 1 addition & 0 deletions src/app/components/Table/TablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const TablePagination: FC<TablePaginationProps> = ({
}}
component={Link}
to={item.page == null ? '' : linkToPage(item.page)}
preventScrollReset={true}
{...item}
sx={isTotalCountClipped && item.type === 'last' ? { pointerEvents: 'none', cursor: 'default' } : {}}
/>
Expand Down
8 changes: 7 additions & 1 deletion src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Outlet, RouteObject } from 'react-router-dom'
import { Outlet, RouteObject, ScrollRestoration } from 'react-router-dom'
import { HomePage } from './app/pages/HomePage'
import { BlocksPage } from './app/pages/BlocksPage'
import { TransactionsPage } from './app/pages/TransactionsPage'
Expand Down Expand Up @@ -30,6 +30,12 @@ const NetworkSpecificPart = () => (
export const routes: RouteObject[] = [
{
errorElement: withDefaultTheme(<RoutingErrorPage />),
element: (
<>
<ScrollRestoration />
<Outlet />
</>
),
children: [
{
path: '/',
Expand Down

0 comments on commit e26a5e5

Please sign in to comment.