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 33 *
44 * Reason for modifying:
55 * - Add a logo to the top of the sidebar
6+ * - Scroll to the active item in the sidebar
67 */
78
8- import React from 'react' ;
9+ import React , { useEffect } from 'react' ;
10+ import { useLocation } from '@docusaurus/router' ;
911import DocSidebar from '@theme-original/DocSidebar' ;
1012import type { Props } from '@theme/DocSidebar' ;
1113
1214import Logo from '@theme-original/Logo' ;
1315
1416export 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+
1528 return (
1629 < >
1730 < Logo />
You can’t perform that action at this time.
0 commit comments