Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Copy Icon is not restoring back from right tick ,when Copied #3178

Merged
merged 3 commits into from
Jan 15, 2025

Conversation

aliahmadCode
Copy link
Contributor

@aliahmadCode aliahmadCode commented Jan 15, 2025

Fixes #3177

PR Type

Bug

What is the current behavior?

Currently, It is copying and then not restoring back to copy icon after some timeout

Issue Number: #3177

What is the new behavior?

Now, I have added the setTimeout to 2s to toggle back to copy icon.

@@ -9,12 +14,20 @@ export class CopyButtonComponent {
public elRef = inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);
public copied = false;

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

onCopy() {
const preRef = this.elRef.nativeElement.querySelector('pre:not(.hide)');
if (!preRef) {
return;
}
navigator.clipboard.writeText(preRef.firstChild.textContent);
this.copied = true;
this.cdr.detectChanges();

setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
setTimeout(() => {
this.revertIconTimeout = setTimeout(() => {

Copy link
Member

Choose a reason for hiding this comment

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

should we assign the result of the setTimeout call to a property and clearTimeout in the onDestroy lifecycle hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented the suggested change, and it was a great idea—thank you!

@kamilmysliwiec kamilmysliwiec merged commit 039162a into nestjs:master Jan 15, 2025
4 checks passed
@kamilmysliwiec
Copy link
Member

LGTM

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.

Copy Icon is not restoring back from right tick ,when Copied.
2 participants