Skip to content

Commit 8d0906d

Browse files
committed
1 parent f9ab0fa commit 8d0906d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

website/siteConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const siteConfig = {
109109
'https://buttons.github.io/buttons.js',
110110
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
111111
'/js/code-block-buttons.js',
112+
'/js/sidenav.js',
112113
],
113114

114115
stylesheets: [

website/static/js/sidenav.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// See https://github.com/reactioncommerce/reaction-docs/pull/686/files
2+
// https://github.com/facebook/Docusaurus/issues/823
3+
4+
document.addEventListener('DOMContentLoaded', () => {
5+
// Find the active nav item in the sidebar
6+
const item = document.getElementsByClassName('navListItemActive')[0]
7+
if (!item) {
8+
return
9+
}
10+
const bounding = item.getBoundingClientRect()
11+
if (
12+
bounding.top >= 0 &&
13+
bounding.bottom <=
14+
(window.innerHeight || document.documentElement.clientHeight)
15+
) {
16+
// Already visible. Do nothing.
17+
} else {
18+
// Not visible. Scroll sidebar.
19+
item.scrollIntoView({ block: 'center', inline: 'nearest' })
20+
document.body.scrollTop = 0
21+
document.documentElement.scrollTop = 0
22+
}
23+
})

0 commit comments

Comments
 (0)