Skip to content

Commit 27de1cd

Browse files
authored
Default to the first ID as being active in scroll detection (#3036)
1 parent ae78fc5 commit 27de1cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/gitbook/src/components/hooks/useScrollActiveId.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export function useScrollActiveId(
1212
) {
1313
const { rootMargin, threshold = 0.5 } = options;
1414

15-
const [activeId, setActiveId] = React.useState<string | null>(null);
15+
const [activeId, setActiveId] = React.useState<string>(ids[0]);
1616
const sectionsIntersectingMap = React.useRef<Map<string, boolean>>(new Map());
1717

1818
React.useEffect(() => {
19-
setActiveId(null);
19+
const defaultActiveId = ids[0];
20+
setActiveId((activeId) => (ids.indexOf(activeId) !== -1 ? activeId : defaultActiveId));
2021

2122
if (typeof IntersectionObserver === 'undefined') {
2223
return;

0 commit comments

Comments
 (0)