Skip to content

Commit 2920d5b

Browse files
committed
fix: TOC 미작동 버그 수정
1 parent 971a750 commit 2920d5b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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}

src/components/post/table-of-contents.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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}

0 commit comments

Comments
 (0)