Skip to content

[root-wrapper] feat(ui): Add copy-to-clipboard button on hover for inline code snippets in blog posts#7791

Open
akshatsinghai6682-sketch wants to merge 4 commits into
layer5io:masterfrom
akshatsinghai6682-sketch:feat/inline-code-copy-button
Open

[root-wrapper] feat(ui): Add copy-to-clipboard button on hover for inline code snippets in blog posts#7791
akshatsinghai6682-sketch wants to merge 4 commits into
layer5io:masterfrom
akshatsinghai6682-sketch:feat/inline-code-copy-button

Conversation

@akshatsinghai6682-sketch

@akshatsinghai6682-sketch akshatsinghai6682-sketch commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Description
This PR fixes #7790

Added a copy-to-clipboard button that appears on hover for inline code snippets in blog posts.

Changes

  • Added InlineCode component in root-wrapper.js
  • Copy icon 📋 appears on hover using opacity transition
  • Shows ✅ confirmation for 2 seconds after copying
  • Uses navigator.clipboard.writeText() API
  • No change to existing inline code styling

Screenshots/Demo

Screen.Recording.2026-06-14.at.4.40.48.PM.mov

Notes for Reviewers
The InlineCode component is added to the MDXProvider components in root-wrapper.js. It wraps the existing <code> tag without modifying its styles, so all existing styling is preserved.

Signed commits

  • Yes, I signed my commits.

Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview deployment: https://layer5.io/pr-preview/pr-7791/

Note: Preview may take a moment (GitHub Pages deployment in progress). Please wait and refresh. Track deployment here

@hortison hortison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@Rajesh-Nagarajan-11 Rajesh-Nagarajan-11 self-requested a review June 13, 2026 12:52

@KatalKavya96 KatalKavya96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akshatsinghai6682-sketch Thanks for working on this.

I noticed two things while reviewing/testing this:

  1. The emoji icons for copy/success should be replaced with the projects existing icon component or a proper SVG icon so the UI remains consistent across browsers and themes.

  2. The current copy logic uses children directly, but it does not seem to copy all inline code text reliably in some cases. A better approach would be to attach a ref to the rendered <code> element and copy codeRef.current.textContent, so the copied value matches the actual visible inline code.

Could you please update the implementation accordingly and also confirm that inline code copying works across blog/docs MDX pages without affecting existing code block rendering?

Comment thread root-wrapper.js Outdated
Comment thread root-wrapper.js Outdated
@akshatsinghai6682-sketch

Copy link
Copy Markdown
Contributor Author

Sure @KatalKavya96 thanks for the feedback

@Bhumikagarggg

Copy link
Copy Markdown
Contributor

@akshatsinghai6682-sketch Thank you for your contribution! Let's discuss this during the website call tomorrow at 5:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂

@akshatsinghai6682-sketch

akshatsinghai6682-sketch commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Sure @Bhumikagarggg i have added it is an agenda item please verify and can u plz clarify what is this meeting about and where can I get the access to its links

Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
@akshatsinghai6682-sketch

akshatsinghai6682-sketch commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

@KatalKavya96 Thank you for the feedback! I have addressed both the review comments:

  1. Replaced emoji icons (📋 ✅) with IoIosCopy and IoIosCheckmark from @react-icons/all-files which is already used in the project for consistency.
  2. Added a ref to the <code> element and using codeRef.current?.textContent for copying the actual visible text instead of children.
Screen.Recording.2026-06-14.at.4.40.48.PM.mov

Please take a look!

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.

[Feature]: Add copy-to-clipboard button on hover for inline code snippets in blog posts

5 participants