Skip to content

Commit ac15f13

Browse files
committed
Clears previous timeout when copying
Ensures that only one timeout is active for hiding the "copied" tooltip, preventing potential issues when copying multiple times in quick succession. This is achieved by clearing any existing timeout before setting a new one.
1 parent dc19641 commit ac15f13

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Frontend/src/components/CopyToClipboard.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { Tippy, TippyComponent } from "vue-tippy";
3-
import { useTemplateRef } from "vue";
3+
import { ref, useTemplateRef, watch } from "vue";
44
55
const props = withDefaults(
66
defineProps<{
@@ -11,14 +11,16 @@ const props = withDefaults(
1111
);
1212
1313
const tippyRef = useTemplateRef<TippyComponent | null>("tippyRef");
14-
let timeoutId: number;
14+
const timeoutId = ref(0);
1515
1616
async function copyToClipboard() {
1717
await navigator.clipboard.writeText(props.value);
18-
window.clearTimeout(timeoutId);
18+
1919
tippyRef.value?.show();
20-
timeoutId = window.setTimeout(() => tippyRef.value?.hide(), 3000);
20+
timeoutId.value = window.setTimeout(() => tippyRef.value?.hide(), 3000);
2121
}
22+
23+
watch(timeoutId, (_, previousTimeoutId) => window.clearTimeout(previousTimeoutId));
2224
</script>
2325

2426
<template>

0 commit comments

Comments
 (0)