Skip to content

fix: stop hidden copy button blocking code text#5247

Open
cookesan wants to merge 3 commits into
vuejs:mainfrom
cookesan:code-copy-pointer-events
Open

fix: stop hidden copy button blocking code text#5247
cookesan wants to merge 3 commits into
vuejs:mainfrom
cookesan:code-copy-pointer-events

Conversation

@cookesan

@cookesan cookesan commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

Keeps code-block copy buttons from covering selectable code text on narrow screens by reserving a small mobile action row above the code content. The copy button still becomes usable on hover or focus, and desktop code blocks keep the existing layout.

Linked Issues

Fixes #5120

Additional Context

Checks:

  • pnpm -F=tests-e2e test markdown-extensions/markdown-extensions.test.ts
  • pnpm check
  • pnpm docs:build

@brc-dd

brc-dd commented Jun 28, 2026

Copy link
Copy Markdown
Member

Doesn't really fix the original issue. .vp-doc [class*='language-']:hover will match the case described in the issue and it will gain pointer-events even with the changes. I don't think there is any good fix for this other than to move the copy button outside.

@cookesan

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I pushed 6fa626c to keep the button above the selectable code content on narrow screens instead of relying on the hidden state. The regression now checks the hover-active case too.

Local checks:

  • pnpm -F=tests-e2e test markdown-extensions/markdown-extensions.test.ts
  • pnpm check
  • pnpm docs:build

@brc-dd

brc-dd commented Jun 28, 2026

Copy link
Copy Markdown
Member

hmm, yeah it works, but not really liking the extra space on top:

image

Maybe we should position the button outside the code block (like outside that background), as a regular button in the mobile view (hover is bad from the UX perspective on mobiles anyway)

image

Need to check how it works with code groups / titles though, especially which are longer (where a scrollbar is rendered for tabs). Don't think a padding-right can be decided for tabs without adjusting the structure. Maybe we can have better control when the title bar plugin is a part of the core.

@cookesan

Copy link
Copy Markdown
Contributor Author

Thanks, agreed. I pushed ca9c410 to move the mobile copy button out of the code block background instead of adding top padding inside pre. The mobile rule now makes the button visible as a regular control while keeping the desktop hover behavior unchanged.

I also expanded the e2e coverage for:

  • plain code blocks
  • code inside custom containers
  • code groups with a long scrollable tab row

Checks:

  • pnpm -F=tests-e2e test markdown-extensions/markdown-extensions.test.ts
  • pnpm check
  • pnpm docs:build

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.

The copy button obstructs the text selection and code copying within the code blocks in mobile view.

2 participants