Skip to content

Commit 36827fb

Browse files
committed
DIGG-482: attemting to fix stickynav issues
1 parent 269ed76 commit 36827fb

File tree

2 files changed

+21
-17
lines changed
  • components/navigation/sticky-nav
  • features/search/search-page/search-page-content

2 files changed

+21
-17
lines changed

components/navigation/sticky-nav/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ export const StickyNav: FC<StickyNavProps> = ({ menuItems, menuHeading }) => {
4040
const watchScroll = () => {
4141
if (isScrolling.current) return;
4242

43-
for (const item of menuItems) {
44-
const element = document.getElementById(item.id);
45-
if (element && isInView(element)) {
46-
setActiveItemId(item.id);
47-
history.replaceState(null, "", `#${item.id}`);
48-
break;
43+
requestAnimationFrame(() => {
44+
for (const item of menuItems) {
45+
const element = document.getElementById(item.id);
46+
if (element && isInView(element)) {
47+
setActiveItemId(item.id);
48+
history.replaceState(null, "", `#${item.id}`);
49+
break;
50+
}
4951
}
50-
}
52+
});
5153
};
5254

53-
const interval = setInterval(watchScroll, 100);
54-
return () => clearInterval(interval);
55+
window.addEventListener("scroll", watchScroll, { passive: true });
56+
watchScroll();
57+
58+
return () => window.removeEventListener("scroll", watchScroll);
5559
}, [isLargeScreen, menuItems]);
5660

5761
const handleClick = (e: MouseEvent<HTMLAnchorElement>, id: string) => {

features/search/search-page/search-page-content/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ export const SearchPageContent: FC<SearchProps> = () => {
249249
))}
250250
</ul>
251251
)}
252+
{searchResult?.hits && (
253+
<Pagination
254+
totalResults={searchResult?.count || 0}
255+
itemsPerPage={PER_PAGE}
256+
pageNumber={pageNumber}
257+
changePage={changePage}
258+
/>
259+
)}
252260
</div>
253-
{searchResult?.hits && (
254-
<Pagination
255-
totalResults={searchResult?.count || 0}
256-
itemsPerPage={PER_PAGE}
257-
pageNumber={pageNumber}
258-
changePage={changePage}
259-
/>
260-
)}
261261
</Container>
262262
</div>
263263
</div>

0 commit comments

Comments
 (0)