File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 3
3
*
4
4
* Reason for modifying:
5
5
* - Add a logo to the top of the sidebar
6
+ * - Scroll to the active item in the sidebar
6
7
*/
7
8
8
- import React from 'react' ;
9
+ import React , { useEffect } from 'react' ;
10
+ import { useLocation } from '@docusaurus/router' ;
9
11
import DocSidebar from '@theme-original/DocSidebar' ;
10
12
import type { Props } from '@theme/DocSidebar' ;
11
13
12
14
import Logo from '@theme-original/Logo' ;
13
15
14
16
export default function DocSidebarWrapper ( props : Props ) : JSX . Element {
17
+ const location = useLocation ( ) ;
18
+
19
+ useEffect ( ( ) => {
20
+ setTimeout ( ( ) => {
21
+ const activeItem = document . querySelector ( '.menu__link--active' ) ;
22
+ if ( activeItem && activeItem . scrollIntoView ) {
23
+ activeItem . scrollIntoView ( { block : 'center' , behavior : 'auto' } ) ;
24
+ }
25
+ } , 100 ) ;
26
+ } , [ location . pathname ] ) ;
27
+
15
28
return (
16
29
< >
17
30
< Logo />
You can’t perform that action at this time.
0 commit comments