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

fix(docs): fix jumplinks demo #10899

Closed
wants to merge 1 commit into from
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
Loading
Loading