Skip to content

Commit 05372f1

Browse files
committed
fix: Copy Icon is not restoring back from right tick ,when Copied
1 parent 32203b0 commit 05372f1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/app/shared/components/copy-button/copy-button.component.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Component, ElementRef, inject } from '@angular/core';
1+
import {
2+
Component,
3+
ElementRef,
4+
inject,
5+
ChangeDetectorRef,
6+
} from '@angular/core';
27

38
@Component({
49
selector: 'app-copy-button',
@@ -9,12 +14,20 @@ export class CopyButtonComponent {
914
public elRef = inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);
1015
public copied = false;
1116

17+
public cdr = inject<ChangeDetectorRef>(ChangeDetectorRef);
18+
1219
onCopy() {
1320
const preRef = this.elRef.nativeElement.querySelector('pre:not(.hide)');
1421
if (!preRef) {
1522
return;
1623
}
1724
navigator.clipboard.writeText(preRef.firstChild.textContent);
1825
this.copied = true;
26+
this.cdr.detectChanges();
27+
28+
setTimeout(() => {
29+
this.copied = false;
30+
this.cdr.detectChanges();
31+
}, 2000);
1932
}
2033
}

0 commit comments

Comments
 (0)