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
20 changes: 20 additions & 0 deletions packages/documentation-framework/hooks/useIsStuck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState, useLayoutEffect } from 'react';

export const useIsStuck = (stickyElementId) => {
const [isStuck, setIsStuck] = useState(false);

useLayoutEffect(() => {
const scrollElement = document.getElementById('ws-page-main');
const stickyElement = document.getElementById(stickyElementId);

const syncFromScroll = () => {
setIsStuck(scrollElement.scrollTop > stickyElement.getBoundingClientRect().top);
};

syncFromScroll();
scrollElement.addEventListener('scroll', syncFromScroll, { passive: true });
return () => scrollElement.removeEventListener('scroll', syncFromScroll);
}, []);

return isStuck;
};
7 changes: 5 additions & 2 deletions packages/documentation-framework/templates/mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { capitalize, getTitle, slugger, trackEvent } from '../helpers';
import './mdx.css';
import { convertToReactComponent } from '@patternfly/ast-helpers';
import { FunctionsTable } from '../components/functionsTable/functionsTable';
import { useIsStuck } from '../hooks/useIsStuck';

const MDXChildTemplate = ({ Component, source, toc = [], index = 0, id }) => {
const {
Expand Down Expand Up @@ -167,6 +168,8 @@ const MDXChildTemplate = ({ Component, source, toc = [], index = 0, id }) => {
};

export const MDXTemplate = ({ title, sources = [], path, id, componentsData }) => {
const isStickyStuck = useIsStuck('ws-sticky-nav-tabs');

const hasFeedbackButton = process.env.hasFeedbackButton;
const isDeprecated =
sources.some((source) => source.source === 'react-deprecated' || source.source === 'html-deprecated') &&
Expand Down Expand Up @@ -307,8 +310,8 @@ export const MDXTemplate = ({ title, sources = [], path, id, componentsData }) =
</Content>
</PageSection>
{showTabs && (
<PageSection id="ws-sticky-nav-tabs" stickyOnBreakpoint={{ default: 'top' }} type="tabs">
<div className="pf-v6-c-tabs pf-m-page-insets pf-m-no-border-bottom">
<PageSection id="ws-sticky-nav-tabs" stickyBase="top" isStickyStuck={isStickyStuck} type="tabs">
<div className="pf-v6-c-tabs pf-m-page-insets">
<ul className="pf-v6-c-tabs__list">
{sourceKeys.map((source, index) => (
<li
Expand Down
Loading