From 95ecf33d8bf7be5abce408ef26a244ec8014cb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pet=C5=99=C3=ADk?= <77832970+Dominik-Petrik@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:34:28 +0200 Subject: [PATCH] fix(JumpLinks) jump links dont work after skipToContent (#9360) * fix(JumpLinks) jump links dont work after skipToContent * Updated conditional for refreshing newScrollItems --------- Co-authored-by: Eric Olkowski --- .../react-core/src/components/JumpLinks/JumpLinks.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx index dc66f560ff4..953b163d128 100644 --- a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx +++ b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx @@ -114,11 +114,15 @@ export const JumpLinks: React.FunctionComponent = ({ const scrollPosition = Math.ceil(scrollableElement.scrollTop + offset); window.requestAnimationFrame(() => { let newScrollItems = scrollItems; - // Items might have rendered after this component. Do a quick refresh. - if (!newScrollItems[0] || newScrollItems.includes(null)) { + // Items might have rendered after this component or offsetTop values may need + // to be updated. Do a quick refresh. + const requiresRefresh = + newScrollItems.every((e) => !e?.offsetTop) || !newScrollItems[0] || newScrollItems.includes(null); + if (requiresRefresh) { newScrollItems = getScrollItems(children, []); setScrollItems(newScrollItems); } + const scrollElements = newScrollItems .map((e, index) => ({ y: e ? e.offsetTop : null,