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

chore(jumplinks): fix overflow in jumplinks demo #11054

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ import {
Sidebar,
SidebarContent,
SidebarPanel,
getResizeObserver,
DrawerContext
} 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 JumpLinksWrapper = ({ headings }) => {
const { drawerContentRef } = React.useContext(DrawerContext);

return (
<JumpLinks
isVertical={true}
label="Jump to section"
scrollableRef={drawerContentRef}
offset={offsetHeight}
expandable={{ default: 'expandable', md: 'nonExpandable' }}
>
{headings.map((heading) => (
Expand All @@ -47,25 +43,9 @@ const JumpLinksWrapper = ({ offsetHeight, headings }) => {
export const JumpLinksWithDrawer = () => {
const headings = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];

const [offsetHeight, setOffsetHeight] = React.useState(0);
const [isExpanded, setIsExpanded] = React.useState(false);
const drawerRef = React.useRef();

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 + breadcrumb.offsetHeight + drawerToggleSection.offsetHeight);
},
true
);
}, []);

const onCloseClick = () => {
setIsExpanded(false);
};
Expand Down Expand Up @@ -95,14 +75,14 @@ export const JumpLinksWithDrawer = () => {
<Sidebar>
<SidebarPanel variant="sticky">
<PageSection>
<JumpLinksWrapper offsetHeight={offsetHeight} headings={headings} />
<JumpLinksWrapper headings={headings} />
</PageSection>
</SidebarPanel>
<SidebarContent>
<PageSection id="drawer-toggle" stickyOnBreakpoint={{ default: 'top' }}>
<Button onClick={onToggleClick}>Toggle drawer</Button>
</PageSection>
<PageSection>
<PageSection hasOverflowScroll>
<Content>
{headings.map((heading) => (
<div key={heading} style={{ maxWidth: '800px', marginBottom: '32px' }}>
Expand Down
Loading