1 | // @ts-check |
||
2 | |||
3 | customElements.define( |
||
0 ignored issues
–
show
|
|||
4 | 'pc-dialog-trigger', |
||
5 | class extends HTMLElement { |
||
0 ignored issues
–
show
|
|||
6 | connectedCallback() { |
||
7 | const dialogId = this.getAttribute('dialog'); |
||
8 | |||
9 | if (!dialogId) { |
||
10 | throw new Error('"dialog" attribute is required'); |
||
11 | } |
||
12 | |||
13 | const dialog = /** @type {HTMLDialogElement|null} */ (document.getElementById( |
||
14 | dialogId |
||
15 | )); |
||
16 | |||
17 | if (!dialog) { |
||
18 | throw new Error(`element "${dialogId}" does not exist`); |
||
19 | } |
||
20 | |||
21 | const button = this.querySelector('button'); |
||
22 | |||
23 | if (!button) { |
||
24 | return; |
||
25 | } |
||
26 | |||
27 | const submitValue = this.getAttribute('submitValue') || 'submit'; |
||
28 | |||
29 | button.addEventListener('click', event => { |
||
30 | event.preventDefault(); |
||
31 | dialog.showModal(); |
||
32 | }); |
||
33 | |||
34 | dialog.addEventListener('close', () => { |
||
35 | if (dialog.returnValue === submitValue) { |
||
36 | this.dispatchEvent( |
||
37 | new CustomEvent('dialog-trigger:submit', { bubbles: true }) |
||
0 ignored issues
–
show
The variable
CustomEvent seems to be never declared. If this is a global, consider adding a /** global: CustomEvent */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
38 | ); |
||
39 | } |
||
40 | }); |
||
41 | } |
||
42 | } |
||
43 | ); |
||
44 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.