From 65231e1a553dd98e0c6e7d778b95f609c4e00a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pet=C5=99=C3=ADk?= Date: Thu, 13 Jul 2023 14:41:44 +0200 Subject: [PATCH 1/2] fix(JumpLinks) jump links dont work after skipToContent --- .../react-core/src/components/JumpLinks/JumpLinks.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx index dc66f560ff4..d2e06ea4f61 100644 --- a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx +++ b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx @@ -115,10 +115,10 @@ export const JumpLinks: React.FunctionComponent = ({ window.requestAnimationFrame(() => { let newScrollItems = scrollItems; // Items might have rendered after this component. Do a quick refresh. - if (!newScrollItems[0] || newScrollItems.includes(null)) { - newScrollItems = getScrollItems(children, []); - setScrollItems(newScrollItems); - } + + newScrollItems = getScrollItems(children, []); + setScrollItems(newScrollItems); + const scrollElements = newScrollItems .map((e, index) => ({ y: e ? e.offsetTop : null, From debf53da15124530dcc6bf5a9dd60e198eee5e60 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Wed, 2 Aug 2023 13:47:57 -0400 Subject: [PATCH 2/2] Updated conditional for refreshing newScrollItems --- .../src/components/JumpLinks/JumpLinks.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx index d2e06ea4f61..953b163d128 100644 --- a/packages/react-core/src/components/JumpLinks/JumpLinks.tsx +++ b/packages/react-core/src/components/JumpLinks/JumpLinks.tsx @@ -114,10 +114,14 @@ 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. - - newScrollItems = getScrollItems(children, []); - setScrollItems(newScrollItems); + // 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) => ({