Skip to content

fix(docs): keep copy button fixed in horizontally scrollable code blocks#16294

Merged
vkarpov15 merged 1 commit into
Automattic:masterfrom
DraXx-Van:fix-copy-button-scroll
May 24, 2026
Merged

fix(docs): keep copy button fixed in horizontally scrollable code blocks#16294
vkarpov15 merged 1 commit into
Automattic:masterfrom
DraXx-Van:fix-copy-button-scroll

Conversation

@DraXx-Van
Copy link
Copy Markdown
Contributor

Fixes #16293

Summary:

  • Wrap each pre element in a .code-block-wrapper container
  • Move copy button positioning to the wrapper instead of the scrollable pre element
  • Update hover selector to target the wrapper

Result:
The copy button now remains fixed in the top-right corner while horizontally scrolling code blocks.

Tested:

  • Copy button appears on hover
  • Copy functionality still works
  • Button remains fixed during horizontal scrolling
  • Verified on actual Mongoose docs pages using browser overrides

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a UI issue in the Mongoose documentation site where the “copy code” button drifts/misaligns when horizontally scrolling within code blocks, by moving the button out of the scrollable <pre> element and anchoring it to a new non-scroll wrapper.

Changes:

  • Wrap each <pre> in a new .code-block-wrapper container and attach the copy button to that wrapper.
  • Move the “position: relative” anchoring from inline JS styling to a dedicated CSS rule on .code-block-wrapper.
  • Update the hover selector so the button shows when hovering the wrapper rather than the <pre>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
docs/js/copy-code.js Wraps each <pre> in a .code-block-wrapper and appends the copy button to the wrapper so it doesn’t scroll with the code content.
docs/css/copy-code.css Adds wrapper positioning and updates the hover selector to target the wrapper for correct button reveal behavior.

Comment thread docs/css/copy-code.css
@vkarpov15 vkarpov15 added this to the 9.6.3 milestone May 24, 2026
@vkarpov15 vkarpov15 merged commit d2699d5 into Automattic:master May 24, 2026
2 checks passed
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.

Docs: Copy button becomes misaligned in horizontally scrollable code blocks

3 participants