Skip to content

Commit

Permalink
Ensure current page is visible on first load
Browse files Browse the repository at this point in the history
Resolves #2626
  • Loading branch information
Gerrit0 committed Jul 5, 2024
1 parent 8932856 commit 34024de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Page navigation now ensures the current page is visible when the page is first loaded, #2626.

## v0.26.3 (2024-06-28)

### Features
Expand Down
14 changes: 13 additions & 1 deletion src/lib/output/themes/default/assets/typedoc/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ export class Application {
iter = iter.parentElement;
}

if (pageLink && !pageLink.checkVisibility()) {
if (pageLink && !checkVisible(pageLink)) {
const top =
pageLink.getBoundingClientRect().top -
document.documentElement.clientHeight / 4;
// If we are showing three columns, this will scroll the site menu down to
// show the page we just loaded in the navigation.
document.querySelector(".site-menu")!.scrollTop = top;
// If we are showing two columns
document.querySelector(".col-sidebar")!.scrollTop = top;
}
}

Expand Down Expand Up @@ -218,3 +220,13 @@ export class Application {
});
}
}

// https://stackoverflow.com/a/5354536/7186598
function checkVisible(elm: Element) {
const rect = elm.getBoundingClientRect();
const viewHeight = Math.max(
document.documentElement.clientHeight,
window.innerHeight,
);
return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
}

0 comments on commit 34024de

Please sign in to comment.