Skip to content

[UI] Fix copy button layout shift and add checkmark confirmation #1144

Merged
Rajesh-Nagarajan-11 merged 12 commits into
layer5io:masterfrom
akshatsinghai6682-sketch:fix-copy-button-shift
Jul 14, 2026
Merged

[UI] Fix copy button layout shift and add checkmark confirmation #1144
Rajesh-Nagarajan-11 merged 12 commits into
layer5io:masterfrom
akshatsinghai6682-sketch:fix-copy-button-shift

Conversation

@akshatsinghai6682-sketch

@akshatsinghai6682-sketch akshatsinghai6682-sketch commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #1143

Notes for Reviewers

Fixes the copy-to-clipboard button used on code blocks site-wide:

  • Layout Stability: Removes the slight position shift that occurred on click (caused by overriding Docsy's default :active { transform: translateY(2px); } press effect with transform: none !important;).
  • Visual Confirmation: Adds a checkmark icon (fa-check) that briefly appears after a successful copy, alongside the existing Bootstrap "Copied!" tooltip, for clearer visual confirmation.
  • Error Prevention: Clears active timeout states on button interaction (clearTimeout) to prevent UI lag or overlapping state updates if the user clicks the button repeatedly.
Screenshot 2026-07-14 at 4 06 03 PM Screenshot 2026-07-14 at 4 06 16 PM

Changes:

  • Added assets/js/click-to-copy.js: A site-level override of Docsy's theme script file. Injected dynamic element generation for the copy buttons (.td-click-to-copy), custom copy handling logic for normal/console logs, and robust promise catches to safeguard failure states.
  • Edited assets/scss/_styles_project.scss: Appended explicit utility rules under .click-to-copy button including &:active { transform: none !important; } to eliminate layout alignment jitters and configured color styles for the target state &.td-click-to-copy--copied.

Testing:

  • Tested locally via make site across multiple documentation pages featuring code blocks. Confirmed both the shift is completely gone, the tooltip handles failures cleanly, and the FontAwesome icon transitions into a checkmark successfully before reverting.

Signed commits

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

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a 'click-to-copy' feature for code blocks, including logic to prune unselectable elements from console blocks and corresponding SCSS styles for the copy button. The review feedback highlights several potential runtime errors: a missing guard check if a code listing does not contain a element, a potential crash if navigator.clipboard is undefined in insecure contexts, and a possible null reference when accessing window.getComputedStyle in certain environments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread assets/js/click-to-copy.js
Comment thread assets/js/click-to-copy.js Outdated
Comment thread assets/js/click-to-copy.js
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.6.3
Preview removed because the pull request was closed.
2026-07-14 15:49 UTC

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

@ishwar170695 ishwar170695 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice UX improvement. One thing I noticed: navigator.clipboard.writeText() is asynchronous, but the success UI (tooltip + checkmark) is shown immediately after calling copyCode(). If the clipboard write is rejected (for example due to permissions or browser restrictions), users would still see "Copied!". Would it make sense to return the writeText() Promise from copyCode() and only switch to the success state after it resolves?

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

Copy link
Copy Markdown
Contributor Author

Nice UX improvement. One thing I noticed: navigator.clipboard.writeText() is asynchronous, but the success UI (tooltip + checkmark) is shown immediately after calling copyCode(). If the clipboard write is rejected (for example due to permissions or browser restrictions), users would still see "Copied!". Would it make sense to return the writeText() Promise from copyCode() and only switch to the success state after it resolves?

Good catch, @ishwar170695 done — copyCode() now returns the writeText() promise, and the success UI only shows after it resolves (with a .catch() for the failure case).

@Bharath314 Bharath314 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.

That's a nice UX change! I have a few comments though. Feel free to go through them whenever you have time. Cheers!

Comment thread assets/js/click-to-copy.js Outdated
Comment thread assets/js/click-to-copy.js Outdated
Comment thread assets/scss/_styles_project.scss
Comment thread assets/js/click-to-copy.js Outdated
Comment thread assets/js/click-to-copy.js Outdated
Comment thread assets/js/click-to-copy.js Outdated
akshatsinghai6682-sketch and others added 5 commits July 10, 2026 20:32
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
Co-authored-by: Bharath Valaboju <69413757+Bharath314@users.noreply.github.com>
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
Comment thread assets/js/click-to-copy.js Outdated
Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>

@Bharath314 Bharath314 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.

LGTM! 🚀

@Sbragul26 Sbragul26 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.

LGTM 👍

Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
@akshatsinghai6682-sketch akshatsinghai6682-sketch changed the title [UI] Fix copy button shift on click and add checkmark confirmation [UI] [UI] Fix copy button shift and integrate Sistent copy/checkmark confirmation Jul 13, 2026
@akshatsinghai6682-sketch

Copy link
Copy Markdown
Contributor Author

Hi @KhushamBansal I have updated the implementation to use the official Sistent design system as we discussed in today's meet CopyIcon and CheckIcon SVGs directly, completely replacing the legacy FontAwesome layout toggles. The PR description has also been updated to reflect this consistency match. Please review whenever possible Thank You!

@akshatsinghai6682-sketch akshatsinghai6682-sketch changed the title [UI] [UI] Fix copy button shift and integrate Sistent copy/checkmark confirmation [UI] Fix copy button shift and integrate Sistent copy/checkmark confirmation Jul 13, 2026
Comment thread assets/js/click-to-copy.js Outdated
… checkmark fixes

Signed-off-by: Akshat Singhai <akshatsinghai6682@gmail.com>
@akshatsinghai6682-sketch akshatsinghai6682-sketch changed the title [UI] Fix copy button shift and integrate Sistent copy/checkmark confirmation [UI] Fix copy button layout shift and add checkmark confirmation Jul 14, 2026
@akshatsinghai6682-sketch

Copy link
Copy Markdown
Contributor Author

@Sbragul26 @KhushamBansal I have reverted my changes to font awesome this pr is now ready for review plz review whenever possible Thank You

@KhushamBansal KhushamBansal 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.

LGTM!!

@Rajesh-Nagarajan-11
Rajesh-Nagarajan-11 merged commit 789df86 into layer5io:master Jul 14, 2026
3 of 4 checks passed
@welcome

welcome Bot commented Jul 14, 2026

Copy link
Copy Markdown

        Thank you for contributing to the Layer5 community! 🎉 \ \ Congrats! \ \         ⭐ Please leave a star on the project. 😄

@akshatsinghai6682-sketch
akshatsinghai6682-sketch deleted the fix-copy-button-shift branch July 14, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI] Copy button on code blocks shifts on click and gives no checkmark confirmation

6 participants