Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Expose `mainContentBodyRef` in order to control main body behaviour (e.g. scroll to top on page change)

## [4.1.1] - 2024-07-18

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from "classnames";
import { PropsWithChildren, ReactNode } from "react";
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";
import "../../../../styles/Layout/index.scss";
import { PanelSideBar } from "./PanelSideBar/PanelSidebar";
import { PanelSideBarLayoutContent } from "./PanelSideBarLayoutContent";
Expand Down Expand Up @@ -38,6 +38,11 @@ export interface PanelSideBarLayoutProps extends PropsWithChildren {
* If use the responsive layout when the screen is sm in order to remove the sidebar overlay.
*/
useResponsiveLayout?: boolean;

/**
* the main content body ref
*/
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
}

export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(props: PanelSideBarLayoutProps) => {
Expand All @@ -50,6 +55,7 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
collapsible = true,
useToggleButton = false,
useResponsiveLayout = false,
mainContentBodyRef,
} = props;

const { isSidebarOpen, toggleSidebar, renderFirstItemsLevelAsTiles } = usePanelSideBarContext<TPanelItemId, TPanelItem>();
Expand All @@ -76,7 +82,9 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
>
<PanelSideBar<TPanelItemId, TPanelItem> />
{collapsible && !useToggleButton && <PanelSideBarToggle onClick={toggleSidebar} toggled={!isSidebarOpen} />}
<PanelSideBarLayoutContent footer={footer}>{children}</PanelSideBarLayoutContent>
<PanelSideBarLayoutContent footer={footer} mainContentBodyRef={mainContentBodyRef}>
{children}
</PanelSideBarLayoutContent>
</section>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { PropsWithChildren, ReactNode } from "react";
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";

interface PanelSideBarLayoutContentProps extends PropsWithChildren {
footer?: ReactNode;
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
}

export const PanelSideBarLayoutContent = (props: PanelSideBarLayoutContentProps) => {
const { children, footer } = props;
const { children, footer, mainContentBodyRef } = props;

return (
<section id="main-content-body" className="content">
<section ref={mainContentBodyRef} id="main-content-body" className="content">
<main className="container-fluid">{children}</main>
<footer hidden={!footer} className="py-4 bg-light mt-auto">
<div className="mx-4">
Expand Down