Skip to content

Commit c72d0b7

Browse files
committed
Make the sonar code quality thing a bit happier
1 parent 65a4e60 commit c72d0b7

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/uui-copy/lib/UUICopyEvent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
22
import { UUICopyElement } from './uui-copy.element';
33

4+
interface UUICopyEventInit extends EventInit {
5+
detail?: { text: string };
6+
}
7+
48
export class UUICopyEvent extends UUIEvent<{ text: string }, UUICopyElement> {
59
public static readonly COPIED: string = 'copied';
610
public static readonly COPYING: string = 'copying';
711

8-
constructor(evName: string, eventInit: any | null = {}) {
12+
constructor(evName: string, eventInit: UUICopyEventInit = {}) {
913
super(evName, {
1014
...{ bubbles: true },
1115
...eventInit,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
8383
// Used to store the value that will be copied to the clipboard
8484
#valueToCopy = '';
8585

86-
#onClick = async (e: Event) => {
86+
readonly #onClick = async (e: Event) => {
8787
const button = e.target as UUIButtonElement;
8888
button.state = 'waiting';
8989

@@ -96,7 +96,7 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
9696
const el = document.getElementById(this.copyFrom);
9797
if (el) {
9898
console.log('Element found to copy from', el);
99-
this.#valueToCopy = el.textContent || el.innerText || '';
99+
this.#valueToCopy = el.textContent ?? el.innerText ?? '';
100100

101101
// Override the value to copy ,if the element has a value property
102102
// Such as uui-input or uui-textarea or native inout elements
@@ -123,7 +123,6 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
123123
await navigator.clipboard
124124
.writeText(this.#valueToCopy)
125125
.then(() => {
126-
//button.state = 'success';
127126
this.dispatchEvent(
128127
new UUICopyEvent(UUICopyEvent.COPIED, {
129128
detail: { text: this.#valueToCopy },
@@ -151,7 +150,7 @@ export class UUICopyElement extends LabelMixin('', LitElement) {
151150
</uui-button>`;
152151
}
153152

154-
static styles = [
153+
static readonly styles = [
155154
css`
156155
slot {
157156
pointer-events: none;

0 commit comments

Comments
 (0)