docs: avoid showing "Copied" if copying fails (#3397)

I noticed that in denoland/fresh#3393 it looks like it's possible that
the "Copied"/Check icon will be shown even if copying to clipboard
fails.

This PR changes it so that the Check icon only shows if copy succeeds.
This commit is contained in:
Christian Svensson
2025-09-11 21:37:31 +02:00
committed by GitHub
parent 6fbe0ddcc4
commit c22c20e21f
2 changed files with 7 additions and 16 deletions
+1 -10
View File
@@ -94,16 +94,7 @@ html[data-theme="dark"] ::selection {
background-repeat: no-repeat;
}
.group:not([data-copied]) .group-not-copied {
display: block;
}
.group[data-copied] .group-not-copied {
display: none;
}
.group[data-copied] .group-copied {
display: block;
}
.group[data-copied] .group-not-copied,
.group:not([data-copied]) .group-copied {
display: none;
}
+6 -6
View File
@@ -11,14 +11,14 @@ document.addEventListener("click", async (ev) => {
const code = el.dataset.code;
if (!code) return;
el.dataset.copied = "true";
setTimeout(() => {
delete el.dataset.copied;
}, 1000);
try {
await navigator.clipboard.writeText(code);
el.dataset.copied = "true";
setTimeout(() => {
delete el.dataset.copied;
}, 1000);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
// deno-lint-ignore no-console