-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathclose-panel.js
More file actions
41 lines (36 loc) · 1.25 KB
/
close-panel.js
File metadata and controls
41 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Base from "../../core/base";
import events from "../../core/events";
import utils from "../../core/utils";
export default Base.extend({
name: "close-panel",
trigger: ".close-panel",
init() {
// Close panel support for dialog panels
// Other modals are handled in pat-modal.
const dialog_panel = this.el.closest("dialog");
if (dialog_panel) {
events.add_event_listener(
dialog_panel,
"close-panel",
"close-panel--dialog",
() => {
dialog_panel.close();
}
);
}
this.el.addEventListener("click", async (e) => {
await utils.timeout(0); // Wait for other patterns, like pat-validation.
if (
e.target.matches(":not([formnovalidate])") &&
e.target.matches("[type=submit], button:not([type=button])") &&
this.el.form?.checkValidity() === false
) {
// Prevent closing an invalid form when submitting.
return;
}
this.el.dispatchEvent(
new Event("close-panel", { bubbles: true, cancelable: true })
);
});
},
});