Skip to content

Commit ac50a35

Browse files
committed
Wrap with try/catch & drop the uneeded .then()
1 parent 2a8db77 commit ac50a35

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

packages/uui-text-copy/lib/uui-text-copy.element.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,20 @@ export class UUITextCopyElement extends LabelMixin('', LitElement) {
127127
this.#valueToCopy = beforeCopyEv.detail.text;
128128
}
129129

130-
await navigator.clipboard
131-
.writeText(this.#valueToCopy)
132-
.then(() => {
133-
this.dispatchEvent(
134-
new UUITextCopyEvent(UUITextCopyEvent.COPIED, {
135-
detail: { text: this.#valueToCopy },
136-
}),
137-
);
138-
setTimeout(() => {
139-
button.state = 'success';
140-
}, this.animationStateDelay);
141-
})
142-
.catch(err => {
143-
button.state = 'failed';
144-
console.error('Error copying to clipboard', err);
145-
});
130+
try {
131+
await navigator.clipboard.writeText(this.#valueToCopy);
132+
this.dispatchEvent(
133+
new UUITextCopyEvent(UUITextCopyEvent.COPIED, {
134+
detail: { text: this.#valueToCopy },
135+
}),
136+
);
137+
setTimeout(() => {
138+
button.state = 'success';
139+
}, this.animationStateDelay);
140+
} catch (err) {
141+
button.state = 'failed';
142+
console.error('Error copying to clipboard', err);
143+
}
146144
};
147145

148146
render() {

0 commit comments

Comments
 (0)