Skip to content

fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498

Open
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-494
Open

fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-494

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Apr 4, 2026

Problem

When streamdown is embedded in a layout with two or more nested scroll containers (e.g., an outer overflow-auto sidebar + an inner overflow-auto chat scroll area), the code block copy/download buttons are visible but unclickable.

The root cause: the sticky + pointer-events-none/auto pattern for the action button wrapper causes browser hit-testing to resolve clicks to the code block container div instead of reaching the buttons when there are multiple overflow: auto ancestors.

Fixes #494

Solution

  • Switch the action button wrapper from position: sticky to position: absolute with top-2 right-2
  • Add position: relative to the CodeBlockContainer so absolute positioning is scoped to the code block

This 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: add relative class
  • packages/streamdown/lib/code-block/index.tsx: change outer wrapper from pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end to pointer-events-none absolute top-2 right-2 z-10 flex items-center
  • .changeset/fix-code-block-buttons-absolute.md: patch changeset

Testing

All 982 existing tests pass (pnpm --filter streamdown test). Biome check clean.

…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
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 4, 2026

@sleitor is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Mermaid block action buttons use sticky positioning that causes click event issues in nested scroll containers, identical to the bug fixed in code blocks.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code block copy/download buttons unclickable in nested scroll containers (sticky + pointer-events-none)

1 participant