Skip to content

Commit 0082ca4

Browse files
committed
x
1 parent 30abd51 commit 0082ca4

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Expose `mainContentBodyRef` in order to control main body behaviour (e.g. scroll to top on page change)
13+
1014
## [4.1.1] - 2024-07-18
1115

1216
### Fixed

src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from "classnames";
2-
import { PropsWithChildren, ReactNode } from "react";
2+
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";
33
import "../../../../styles/Layout/index.scss";
44
import { PanelSideBar } from "./PanelSideBar/PanelSidebar";
55
import { PanelSideBarLayoutContent } from "./PanelSideBarLayoutContent";
@@ -38,6 +38,11 @@ export interface PanelSideBarLayoutProps extends PropsWithChildren {
3838
* If use the responsive layout when the screen is sm in order to remove the sidebar overlay.
3939
*/
4040
useResponsiveLayout?: boolean;
41+
42+
/**
43+
* the main content body ref
44+
*/
45+
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
4146
}
4247

4348
export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(props: PanelSideBarLayoutProps) => {
@@ -50,6 +55,7 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
5055
collapsible = true,
5156
useToggleButton = false,
5257
useResponsiveLayout = false,
58+
mainContentBodyRef,
5359
} = props;
5460

5561
const { isSidebarOpen, toggleSidebar, renderFirstItemsLevelAsTiles } = usePanelSideBarContext<TPanelItemId, TPanelItem>();
@@ -76,7 +82,9 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
7682
>
7783
<PanelSideBar<TPanelItemId, TPanelItem> />
7884
{collapsible && !useToggleButton && <PanelSideBarToggle onClick={toggleSidebar} toggled={!isSidebarOpen} />}
79-
<PanelSideBarLayoutContent footer={footer}>{children}</PanelSideBarLayoutContent>
85+
<PanelSideBarLayoutContent footer={footer} mainContentBodyRef={mainContentBodyRef}>
86+
{children}
87+
</PanelSideBarLayoutContent>
8088
</section>
8189
</>
8290
);

src/lib/Layout/PanelSideBarLayout/PanelSideBarLayoutContent.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { PropsWithChildren, ReactNode } from "react";
1+
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";
22

33
interface PanelSideBarLayoutContentProps extends PropsWithChildren {
44
footer?: ReactNode;
5+
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
56
}
67

78
export const PanelSideBarLayoutContent = (props: PanelSideBarLayoutContentProps) => {
8-
const { children, footer } = props;
9+
const { children, footer, mainContentBodyRef } = props;
910

1011
return (
11-
<section id="main-content-body" className="content">
12+
<section ref={mainContentBodyRef} id="main-content-body" className="content">
1213
<main className="container-fluid">{children}</main>
1314
<footer hidden={!footer} className="py-4 bg-light mt-auto">
1415
<div className="mx-4">

0 commit comments

Comments
 (0)