Skip to content

Commit 6cdafcb

Browse files
committed
fix(website): no Copy error without a clipboard, and announce Copied
1 parent 422a5cc commit 6cdafcb

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎website/src/pages/index.tsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,27 @@ function CopyButton({ text }: { text: string }) {
2828
type="button"
2929
className={styles.copyButton}
3030
onClick={() =>
31-
navigator.clipboard.writeText(text).then(
31+
navigator.clipboard?.writeText(text).then(
3232
() => {
3333
setCopied(true);
3434
setTimeout(() => setCopied(false), 1500);
3535
},
3636
() => {
37-
// Clipboard denied (an embedded browser, a policy): the prompt selects
38-
// itself in one click (.agentPrompt pre), so the reader copies by hand.
37+
// No clipboard (an insecure context) or a denied one (an embedded
38+
// browser, a policy): the prompt selects itself in one click
39+
// (.agentPrompt pre), so the reader copies by hand.
3940
},
4041
)
4142
}
4243
>
4344
{copied ? <Check size={13} /> : <Copy size={13} />}
44-
{copied ? (
45-
<Translate id="home.agents.copied">Copied</Translate>
46-
) : (
47-
<Translate id="home.agents.copy">Copy</Translate>
48-
)}
45+
<span aria-live="polite">
46+
{copied ? (
47+
<Translate id="home.agents.copied">Copied</Translate>
48+
) : (
49+
<Translate id="home.agents.copy">Copy</Translate>
50+
)}
51+
</span>
4952
</button>
5053
);
5154
}

0 commit comments

Comments
 (0)