Skip to content

Commit

Permalink
Wrap with try/catch & drop the uneeded .then()
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenbuckley committed Jan 15, 2025
1 parent 2a8db77 commit ac50a35
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/uui-text-copy/lib/uui-text-copy.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,20 @@ export class UUITextCopyElement extends LabelMixin('', LitElement) {
this.#valueToCopy = beforeCopyEv.detail.text;
}

await navigator.clipboard
.writeText(this.#valueToCopy)
.then(() => {
this.dispatchEvent(
new UUITextCopyEvent(UUITextCopyEvent.COPIED, {
detail: { text: this.#valueToCopy },
}),
);
setTimeout(() => {
button.state = 'success';
}, this.animationStateDelay);
})
.catch(err => {
button.state = 'failed';
console.error('Error copying to clipboard', err);
});
try {
await navigator.clipboard.writeText(this.#valueToCopy);
this.dispatchEvent(
new UUITextCopyEvent(UUITextCopyEvent.COPIED, {
detail: { text: this.#valueToCopy },
}),
);
setTimeout(() => {
button.state = 'success';
}, this.animationStateDelay);
} catch (err) {
button.state = 'failed';
console.error('Error copying to clipboard', err);
}
};

render() {
Expand Down

0 comments on commit ac50a35

Please sign in to comment.