Fixed: navigation scroll to active link regression (#1367)

* Defer removal of href

The `href` with the URL of the current page is inspected by `navLink()`, so it should not be removed until after the calls of `navLink()` in `scrollNav()` and `activateNav()`.

As `scrollNav()` follows `activateNav()`, the removal of `href` needs to be left to `scrollNav()`.

* Update CHANGELOG.md
This commit is contained in:
Peter Mosses 2023-10-08 10:37:24 +02:00 committed by GitHub
parent 3d01bc9183
commit ae52352eae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -26,6 +26,7 @@ Code changes to `main` that are *not* in the latest release:
- Fixed: remove href from the navigation link to the current page by [@pdmosses] in [#1356]
- Fixed: improve build time by [@pdmosses] in [#1358]
- Fixed: erroneous parentheses in `site_nav` conditional by [@mattxwang] in [#1366]
- Fixed: navigation scroll to active link regression by [@pdmosses] in [#1367]
{: .warning }
[#1358] moved `_includes/nav.html` to the `_includes/components` directory,
@ -41,6 +42,7 @@ Users who were overriding that file will need to adjust their sites accordingly.
[#1358]: https://github.com/just-the-docs/just-the-docs/pull/1358
[#1360]: https://github.com/just-the-docs/just-the-docs/pull/1360
[#1366]: https://github.com/just-the-docs/just-the-docs/pull/1366
[#1367]: https://github.com/just-the-docs/just-the-docs/pull/1367
## Release v0.6.2

View File

@ -497,6 +497,7 @@ function scrollNav() {
if (targetLink) {
const rect = targetLink.getBoundingClientRect();
document.getElementById('site-nav').scrollBy(0, rect.top - 3*rect.height);
targetLink.removeAttribute('href');
}
}
@ -507,7 +508,6 @@ function activateNav() {
var target = navLink();
if (target) {
target.classList.toggle('active', true);
target.removeAttribute('href');
}
while (target) {
while (target && !(target.classList && target.classList.contains('nav-list-item'))) {