Skip to content

Commit 7385d3f

Browse files
fix(JumpLinks): updated demo code for active item (#12590)
1 parent 8e610ef commit 7385d3f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/react-core/src/components/JumpLinks/JumpLinks.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
142142
return;
143143
}
144144
const scrollPosition = Math.ceil(scrollableElement.scrollTop + offset);
145+
// Take into account the last section not having enough content to trigger a scroll position; without
146+
// checking if at the bottom of the scroll container, the last JumpLinksItem never becomes "active".
147+
const isAtBottom =
148+
Math.ceil(scrollableElement.scrollTop + scrollableElement.clientHeight) >= scrollableElement.scrollHeight;
145149
window.requestAnimationFrame(() => {
146150
let newScrollItems = scrollItems;
147151
// Items might have rendered after this component or offsetTop values may need
@@ -153,6 +157,11 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
153157
setScrollItems(newScrollItems);
154158
}
155159

160+
if (isAtBottom) {
161+
const lastIndex = newScrollItems.length - 1;
162+
return setActiveIndex(lastIndex);
163+
}
164+
156165
const scrollElements = newScrollItems
157166
.map((e, index) => ({
158167
y: e ? e.offsetTop : null,

packages/react-core/src/demos/examples/JumpLinks/JumpLinksScrollspy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const JumpLinksScrollspy: React.FunctionComponent = () => {
7272
isVertical={isVertical}
7373
isCentered={!isVertical}
7474
label="Jump to section"
75-
scrollableSelector=".pf-v6-c-page__main-container"
75+
scrollableSelector=".pf-v6-c-page__main"
7676
offset={offsetHeight}
7777
expandable={{ default: isVertical ? 'expandable' : 'nonExpandable', md: 'nonExpandable' }}
7878
isExpanded

0 commit comments

Comments
 (0)