Skip to content

Commit 092ae6a

Browse files
committed
fix: make code panel scrollable for long algorithm sources
Constrain the panel height chain with min-h-0 and treat the code viewer as the scrollport so long sources (e.g. greedy-vs-dp) can scroll instead of being clipped.
1 parent 22ac7ae commit 092ae6a

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/components/CodePanel.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const algorithmCodeHtml = initialAlgorithmId
2929
data-code-panel-content
3030
data-locale={locale}
3131
data-initial-algorithm-id={initialAlgorithmId}
32-
class="flex flex-col h-full"
32+
class="flex flex-col h-full min-h-0"
3333
>
34-
<div class="flex flex-1 flex-col overflow-hidden">
34+
<div class="flex flex-1 flex-col overflow-hidden min-h-0">
3535
<div
3636
class="flex items-center gap-1 shrink-0 px-2 md:px-3 py-1.5 border-b border-white/[0.06]"
3737
role="group"
@@ -73,7 +73,7 @@ const algorithmCodeHtml = initialAlgorithmId
7373
</div>
7474
</div>
7575

76-
<div data-code-variants class="h-full" set:html={algorithmCodeHtml}></div>
76+
<div data-code-variants class="h-full min-h-0" set:html={algorithmCodeHtml}></div>
7777
</div>
7878

7979
<div

src/components/CodePanelShell.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const panelWidth = "420px"
3535

3636
<div
3737
data-code-panel-shell
38-
class="site-code-panel-shell relative shrink-0 flex z-50 md:z-auto"
38+
class="site-code-panel-shell relative shrink-0 flex self-stretch min-h-0 z-50 md:z-auto"
3939
style={`--code-panel-width: ${panelWidth}`}
4040
data-initial-collapsed={initialCollapsed ? "" : undefined}
4141
data-collapsed={initialCollapsed ? "" : undefined}
@@ -62,7 +62,7 @@ const panelWidth = "420px"
6262

6363
<aside
6464
data-code-panel-panel
65-
class="site-code-panel-panel bg-black overflow-hidden flex flex-col"
65+
class="site-code-panel-panel bg-black overflow-hidden flex flex-col min-h-0 h-full"
6666
style={`width: ${initialCollapsed ? "0px" : panelWidth}`}
6767
aria-label={t.codePanelAriaLabel}
6868
aria-hidden={initialCollapsed ? "true" : "false"}
@@ -92,7 +92,7 @@ const panelWidth = "420px"
9292
</button>
9393
</div>
9494

95-
<div class="w-full h-full flex flex-col min-h-0 relative">
95+
<div class="w-full flex-1 flex flex-col min-h-0 relative">
9696
<CodePanel
9797
locale={locale}
9898
initialAlgorithmId={initialAlgorithmId}

src/styles/global.css

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,48 @@
236236
}
237237
}
238238

239+
/* Keep the scroll chain constrained so long sources can overflow-auto. */
240+
[data-code-variants],
241+
[data-algorithm-code] {
242+
height: 100%;
243+
min-height: 0;
244+
}
245+
246+
[data-algorithm-code] {
247+
display: flex;
248+
flex-direction: column;
249+
overflow: hidden;
250+
}
251+
239252
.code-viewer {
240253
color: var(--foreground);
241254
background: var(--surface);
242255
tab-size: 2;
243-
scrollbar-width: none;
256+
/* pre is the scrollport — height must not grow with content */
257+
flex: 1 1 auto;
258+
min-height: 0;
259+
max-height: 100%;
260+
overflow: auto;
261+
scrollbar-width: thin;
262+
scrollbar-color: color-mix(in srgb, var(--foreground) 18%, transparent) transparent;
244263
opacity: 1;
245264
transition: opacity 160ms cubic-bezier(0.23, 1, 0.32, 1);
246265
}
247266

248267
.code-viewer::-webkit-scrollbar {
249-
display: none;
268+
width: 8px;
269+
height: 8px;
270+
}
271+
272+
.code-viewer::-webkit-scrollbar-thumb {
273+
background: color-mix(in srgb, var(--foreground) 18%, transparent);
274+
border-radius: 999px;
275+
border: 2px solid transparent;
276+
background-clip: content-box;
277+
}
278+
279+
.code-viewer::-webkit-scrollbar-track {
280+
background: transparent;
250281
}
251282

252283
.code-viewer.is-loading {

0 commit comments

Comments
 (0)