Skip to content
Open
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
9 changes: 9 additions & 0 deletions packages/react-core/src/components/JumpLinks/JumpLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
return;
}
const scrollPosition = Math.ceil(scrollableElement.scrollTop + offset);
// Take into account the last section not having enough content to trigger a scroll position; without
// checking if at the bottom of the scroll container, the last JumpLinksItem never becomes "active".
const isAtBottom =
Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;
Comment on lines +147 to +148

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Only treat the container as “at bottom” when it actually scrolls.

When scrollHeight === clientHeight, this condition is true at scrollTop === 0, so a short/non-scrollable page immediately marks the last JumpLink active instead of the first/default item.

Proposed fix
     const isAtBottom =
-      Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;
+      scrollableElement.scrollHeight > scrollableElement.clientHeight &&
+      Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;

Also applies to: 160-162

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/JumpLinks/JumpLinks.tsx` around lines 147
- 148, Update the bottom-detection logic in the JumpLinks scroll handling so it
requires the container to be scrollable before setting isAtBottom, excluding
cases where scrollHeight equals clientHeight. Apply the same guard to the
corresponding logic around the alternate referenced lines, preserving the
existing bottom threshold for genuinely scrollable containers.

window.requestAnimationFrame(() => {
let newScrollItems = scrollItems;
// Items might have rendered after this component or offsetTop values may need
Expand All @@ -153,6 +157,11 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
setScrollItems(newScrollItems);
}

if (isAtBottom) {
const lastIndex = newScrollItems.length - 1;
return setActiveIndex(lastIndex);
}

const scrollElements = newScrollItems
.map((e, index) => ({
y: e ? e.offsetTop : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const JumpLinksScrollspy: React.FunctionComponent = () => {
isVertical={isVertical}
isCentered={!isVertical}
label="Jump to section"
scrollableSelector=".pf-v6-c-page__main-container"
scrollableSelector=".pf-v6-c-page__main"
offset={offsetHeight}
expandable={{ default: isVertical ? 'expandable' : 'nonExpandable', md: 'nonExpandable' }}
isExpanded
Expand Down
Loading