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
Open
fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498sleitor wants to merge 1 commit intovercel:mainfrom
sleitor wants to merge 1 commit intovercel:mainfrom
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
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.