Skip to content

Commit

Permalink
fix(JumpLinks) jump links dont work after skipToContent (#9360)
Browse files Browse the repository at this point in the history
* fix(JumpLinks) jump links dont work after skipToContent

* Updated conditional for refreshing newScrollItems

---------

Co-authored-by: Eric Olkowski <[email protected]>
  • Loading branch information
Dominik-Petrik and thatblindgeye authored Aug 22, 2023
1 parent dab64bb commit 95ecf33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/react-core/src/components/JumpLinks/JumpLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ export const JumpLinks: React.FunctionComponent<JumpLinksProps> = ({
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,
Expand Down

0 comments on commit 95ecf33

Please sign in to comment.