Skip to content
Closed
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
45 changes: 28 additions & 17 deletions packages/react-core/src/demos/JumpLinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,38 @@ ScrollspyH2 = () => {

const [isVertical, setIsVertical] = React.useState(true);
const [offsetHeight, setOffsetHeight] = React.useState(10);
const offsetForPadding = 10;
let masthead;

// Update offset based on the masthead and jump links nav heights.
React.useEffect(() => {
const masthead = document.getElementsByClassName(mastheadStyles.masthead)[0];
const offsetForPadding = 10;

getResizeObserver(
masthead,
() => {
if (isVertical) {
setOffsetHeight(masthead.offsetHeight + offsetForPadding);
} else {
// Append jump links nav height to the masthead height when value exists.
const jumpLinksHeaderHeight = document.getElementsByClassName('pf-m-sticky')[0].offsetHeight;
jumpLinksHeaderHeight && setOffsetHeight(masthead.offsetHeight + jumpLinksHeaderHeight + offsetForPadding);
}
},
true
);
masthead = document.getElementsByClassName(mastheadStyles.masthead)[0];

if (isVertical) {
setOffsetHeight(masthead.offsetHeight + offsetForPadding);
} else {
// Append jump links nav height to the masthead height when value exists.
const jumpLinksHeaderHeight = document.getElementsByClassName('pf-m-sticky')[0].offsetHeight;
jumpLinksHeaderHeight && setOffsetHeight(masthead.offsetHeight + jumpLinksHeaderHeight + offsetForPadding);
}


}, [isVertical]);

getResizeObserver(
document.getElementsByClassName(mastheadStyles.masthead)[0],
() => {
if (isVertical) {
setOffsetHeight(masthead.offsetHeight + offsetForPadding);
} else {
// Append jump links nav height to the masthead height when value exists.
const jumpLinksHeaderHeight = document.getElementsByClassName('pf-m-sticky')[0].offsetHeight;
jumpLinksHeaderHeight && setOffsetHeight(masthead.offsetHeight + jumpLinksHeaderHeight + offsetForPadding);
}
},
true
);

return (
<DashboardWrapper breadcrumb={null} mainContainerId="scrollable-element">
<PageSection>
Expand All @@ -85,7 +96,7 @@ ScrollspyH2 = () => {
isVertical={isVertical}
isCentered={!isVertical}
label="Jump to section"
scrollableSelector="#scrollable-element"
scrollableSelector=".pf-v6-c-page__main-container"
offset={offsetHeight}
expandable={{ default: isVertical ? 'expandable' : 'nonExpandable', md: 'nonExpandable' }}
isExpanded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@patternfly/react-core';
import { DashboardWrapper } from '@patternfly/react-core/dist/js/demos/DashboardWrapper';
import mastheadStyles from '@patternfly/react-styles/css/components/Masthead/masthead';
import breadcrumbStyles from '@patternfly/react-styles/css/components/Breadcrumb/breadcrumb';

const JumpLinksWrapper = ({ offsetHeight, headings }) => {
const { drawerContentRef } = React.useContext(DrawerContext);
Expand Down Expand Up @@ -52,12 +53,14 @@ export const JumpLinksWithDrawer = () => {

React.useEffect(() => {
const masthead = document.getElementsByClassName(mastheadStyles.masthead)[0];
const breadcrumb = document.getElementsByClassName(breadcrumbStyles.breadcrumb)[0];
const drawerToggleSection = document.getElementById('drawer-toggle');
setOffsetHeight(masthead.offsetHeight + breadcrumb.offsetHeight + drawerToggleSection.offsetHeight);

getResizeObserver(
masthead,
() => {
setOffsetHeight(masthead.offsetHeight + drawerToggleSection.offsetHeight);
setOffsetHeight(masthead.offsetHeight + breadcrumb.offsetHeight + drawerToggleSection.offsetHeight);
},
true
);
Expand Down
Loading