@@ -51,7 +51,7 @@ export function Sidebar({
51
51
52
52
const anchors = useMemo ( ( ) => headings . filter ( ( v ) => v . depth === 2 ) , [ headings ] )
53
53
const sidebarRef = useRef < HTMLDivElement > ( null )
54
- const containerRef = useRef < HTMLDivElement > ( null )
54
+ const sortableTreeRef = useRef < HTMLDivElement > ( null )
55
55
const mounted = useMounted ( )
56
56
57
57
useEffect ( ( ) => {
@@ -63,15 +63,14 @@ export function Sidebar({
63
63
} , [ menu ] )
64
64
65
65
useEffect ( ( ) => {
66
- const activeElement = sidebarRef . current ?. querySelector ( 'li.active' )
67
-
66
+ const activeElement = sortableTreeRef . current ?. querySelector ( 'li.active' )
68
67
if ( activeElement && ( window . innerWidth > 767 || menu ) ) {
69
68
const scroll = ( ) => {
70
69
scrollIntoView ( activeElement , {
71
70
block : 'center' ,
72
71
inline : 'center' ,
73
72
scrollMode : 'always' ,
74
- boundary : containerRef . current ,
73
+ boundary : sidebarRef . current ,
75
74
} )
76
75
}
77
76
if ( menu ) {
@@ -93,6 +92,7 @@ export function Sidebar({
93
92
setFocusedItem ( null )
94
93
setIsFolding ( false )
95
94
setMenu ( false )
95
+ sortableTreeRef . current ?. scrollTo ( { top : 0 , behavior : 'smooth' } )
96
96
} , [ isFolding ] )
97
97
98
98
const hasI18n = config . i18n . length > 0
@@ -136,7 +136,7 @@ export function Sidebar({
136
136
? 'max-md:[transform:translate3d(0,0,0)]'
137
137
: 'max-md:[transform:translate3d(0,-100%,0)]' ,
138
138
) }
139
- ref = { containerRef }
139
+ ref = { sidebarRef }
140
140
>
141
141
< div className = "nx-px-4 nx-pt-4 md:nx-hidden" >
142
142
{ renderComponent ( config . search . component , {
@@ -147,7 +147,7 @@ export function Sidebar({
147
147
items = { sortableItems }
148
148
onItemsChanged = { setSortableItems }
149
149
showSidebar = { showSidebar }
150
- sidebarRef = { sidebarRef }
150
+ sidebarRef = { sortableTreeRef }
151
151
/>
152
152
{ mounted && window . innerWidth < 768 && (
153
153
< Menu
0 commit comments