fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498
fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498sleitor wants to merge 2 commits into
Conversation
…lick 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 copy/ download buttons when embedded in 2+ nested scroll containers. Closes vercel#494
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
@sleitor Can you update the vercel (bot) suggested changes, as 'mermaid' also has similar issue |
…ks in nested scroll containers Same fix as code-block (ab0a5ae): switches the mermaid block action button wrapper from position:sticky to position:absolute so that hit-testing works correctly in layouts with multiple nested overflow:auto scroll containers. The mermaid block container already has position:relative, so only the inner toolbar wrapper needed updating. Fixes vercel#494
|
@manjujidagi Good catch! The Mermaid block action buttons (download/copy/fullscreen toolbar) had the same |
|
@sleitor When do you think this will be merged ? I am waiting for this update |
|
@manjujidagi The fix is ready — the remaining blocker is Vercel team authorization for the deployment preview (the standard bot checkpoint for external contributors). Merge timeline is up to the Vercel/streamdown maintainers, but I'll continue to follow up with them. Thanks for your patience! |
Problem
When streamdown is embedded in a layout with two or more nested scroll containers (e.g., an outer
overflow-autosidebar + an inneroverflow-autochat scroll area), the code block copy/download buttons are visible but unclickable.The root cause: the
sticky+pointer-events-none/autopattern for the action button wrapper causes browser hit-testing to resolve clicks to the code block containerdivinstead of reaching the buttons when there are multipleoverflow: autoancestors.Fixes #494
Solution
position: stickytoposition: absolutewithtop-2 right-2position: relativeto theCodeBlockContainerso absolute positioning is scoped to the code blockThis makes buttons reliably clickable in all scroll-container configurations.
Trade-off: Buttons no longer scroll with long code blocks (they stay fixed at the top-right of the code block). This is the same behavior as the workaround documented in the issue, and arguably cleaner UX — the buttons are always visible and always reachable.
Changes
packages/streamdown/lib/code-block/container.tsx: addrelativeclasspackages/streamdown/lib/code-block/index.tsx: change outer wrapper frompointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-endtopointer-events-none absolute top-2 right-2 z-10 flex items-center.changeset/fix-code-block-buttons-absolute.md: patch changesetTesting
All 982 existing tests pass (
pnpm --filter streamdown test). Biome check clean.