Skip to content

Commit 2680e84

Browse files
authored
fix(docs): avoid scrolling to bottom when active sidebar link is not found (#728)
1 parent 375326b commit 2680e84

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • src/generators/legacy-html/assets

src/generators/legacy-html/assets/api.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,19 @@ const setupCopyButton = () => {
203203
function setupSidebarScroll() {
204204
const sidebarLinks = document.querySelectorAll('#column2 a');
205205

206-
let link;
207-
for (link of sidebarLinks) {
206+
let activeLink = null;
207+
for (const link of sidebarLinks) {
208208
if (link.pathname === window.location.pathname) {
209+
activeLink = link;
209210
break;
210211
}
211212
}
212213

213-
if (!link) {
214+
if (!activeLink) {
214215
return;
215216
}
216217

217-
link.scrollIntoView({ behavior: 'smooth', block: 'center' });
218+
activeLink.scrollIntoView({ behavior: 'smooth', block: 'center' });
218219
}
219220

220221
// Initialize either on DOMContentLoaded or immediately if already loaded

0 commit comments

Comments
 (0)