Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/fix-code-block-buttons-absolute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"streamdown": patch
---

fix(code-block): use absolute positioning for action buttons to fix click events in nested scroll containers

Switches the code block action button wrapper from `position: sticky` to
`position: absolute` (with `position: relative` on the container) so that
hit-testing works correctly in layouts with multiple nested `overflow: auto`
scroll containers. Previously, the `sticky` + `pointer-events-none/auto`
pattern caused browsers to mis-route click events to the code block wrapper
rather than the buttons when the component was embedded in 2+ nested scroll
containers.
2 changes: 1 addition & 1 deletion packages/streamdown/lib/code-block/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const CodeBlockContainer = ({
return (
<div
className={cn(
"my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",
"relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",
className
)}
data-incomplete={isIncomplete || undefined}
Expand Down
2 changes: 1 addition & 1 deletion packages/streamdown/lib/code-block/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const CodeBlock = ({
{children ? (
<div
className={cn(
"pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"
"pointer-events-none absolute top-2 right-2 z-10 flex items-center"
)}
>
<div
Expand Down
Loading