Skip to content

Commit 34024de

Browse files
committed
Ensure current page is visible on first load
Resolves #2626
1 parent 8932856 commit 34024de

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- Page navigation now ensures the current page is visible when the page is first loaded, #2626.
6+
37
## v0.26.3 (2024-06-28)
48

59
### Features

src/lib/output/themes/default/assets/typedoc/Application.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ export class Application {
107107
iter = iter.parentElement;
108108
}
109109

110-
if (pageLink && !pageLink.checkVisibility()) {
110+
if (pageLink && !checkVisible(pageLink)) {
111111
const top =
112112
pageLink.getBoundingClientRect().top -
113113
document.documentElement.clientHeight / 4;
114114
// If we are showing three columns, this will scroll the site menu down to
115115
// show the page we just loaded in the navigation.
116116
document.querySelector(".site-menu")!.scrollTop = top;
117+
// If we are showing two columns
118+
document.querySelector(".col-sidebar")!.scrollTop = top;
117119
}
118120
}
119121

@@ -218,3 +220,13 @@ export class Application {
218220
});
219221
}
220222
}
223+
224+
// https://stackoverflow.com/a/5354536/7186598
225+
function checkVisible(elm: Element) {
226+
const rect = elm.getBoundingClientRect();
227+
const viewHeight = Math.max(
228+
document.documentElement.clientHeight,
229+
window.innerHeight,
230+
);
231+
return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
232+
}

0 commit comments

Comments
 (0)