File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,13 +61,13 @@ export default async function RootLayout({
6161 className = { `${ geistSans . variable } ${ geistMono . variable } antialiased` }
6262 >
6363 < ThemeProvider initialTheme = "light" >
64- < div className = "flex overflow-y-hidden" >
64+ < div className = "flex h-screen overflow-y-hidden" >
6565 < div className = "fixed top-0 left-0 z-50 hidden h-screen w-80 p-4 md:block" >
6666 < Sidebar categories = { categories } />
6767 </ div >
6868 < div
6969 id = "content-wrapper"
70- className = "flex-1 overflow-x-hidden px-4 pb-24 md:pb-0 md:pl-84 lg:pr-0"
70+ className = "flex-1 overflow-x-hidden overflow-y-auto px-4 pb-24 md:pb-0 md:pl-84 lg:pr-0"
7171 >
7272 < ScrollRestoration />
7373 { children }
Original file line number Diff line number Diff line change @@ -78,6 +78,22 @@ export const TableOfContents = () => {
7878 < li key = { id } style = { { paddingLeft : `${ ( level - 1 ) * 12 } px` } } >
7979 < a
8080 href = { `#${ id } ` }
81+ onClick = { ( e ) => {
82+ e . preventDefault ( ) ;
83+ const target = document . getElementById ( id ) ;
84+ if ( target ) {
85+ const wrapper = document . getElementById ( "content-wrapper" ) ;
86+ if ( wrapper ) {
87+ const wrapperRect = wrapper . getBoundingClientRect ( ) ;
88+ const targetRect = target . getBoundingClientRect ( ) ;
89+ wrapper . scrollTo ( {
90+ top : wrapper . scrollTop + targetRect . top - wrapperRect . top - 40 ,
91+ behavior : "smooth" ,
92+ } ) ;
93+ }
94+ }
95+ window . history . pushState ( null , "" , `#${ id } ` ) ;
96+ } }
8197 className = "relative block text-sm leading-snug transition-all duration-200"
8298 >
8399 { text }
You can’t perform that action at this time.
0 commit comments