inclusive-elements 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { createFocusTrap as
|
|
5
|
-
import { hello as
|
|
6
|
-
const
|
|
1
|
+
var d = Object.defineProperty;
|
|
2
|
+
var l = (n, s, t) => s in n ? d(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
|
|
3
|
+
var o = (n, s, t) => (l(n, typeof s != "symbol" ? s + "" : s, t), t);
|
|
4
|
+
import { createFocusTrap as p } from "focus-trap";
|
|
5
|
+
import { hello as f, goodbye as m } from "hello-goodbye";
|
|
6
|
+
const a = class a extends HTMLElement {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
o(this, "focusTrap");
|
|
10
|
+
o(this, "focusTrapPaused", !1);
|
|
11
|
+
o(this, "connected", !1);
|
|
11
12
|
const t = document.createElement("template");
|
|
12
13
|
t.innerHTML = `
|
|
13
14
|
<div part="backdrop" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
|
|
@@ -15,26 +16,34 @@ const n = class n extends HTMLElement {
|
|
|
15
16
|
`;
|
|
16
17
|
const i = this.attachShadow({ mode: "open" });
|
|
17
18
|
i.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
|
|
18
|
-
var
|
|
19
|
-
this.hasAttribute("static") ? (
|
|
20
|
-
}), this.focusTrap =
|
|
19
|
+
var e;
|
|
20
|
+
this.hasAttribute("static") ? (e = a.attention) == null || e.call(a, i.children[1]) : this.close();
|
|
21
|
+
}), this.focusTrap = p(this, {
|
|
21
22
|
escapeDeactivates: !1,
|
|
22
23
|
allowOutsideClick: !0,
|
|
23
24
|
preventScroll: !0,
|
|
24
|
-
|
|
25
|
+
// This runs after a delay on every activate and unpause, so the trap
|
|
26
|
+
// may be paused by then. If focus is already inside the modal (e.g.
|
|
27
|
+
// returned there by an overlay that has just closed), leave it.
|
|
28
|
+
initialFocus: () => {
|
|
29
|
+
if (this.focusTrap.paused)
|
|
30
|
+
return !1;
|
|
31
|
+
if (!this.contains(document.activeElement))
|
|
32
|
+
return this.querySelector("[autofocus]") || void 0;
|
|
33
|
+
},
|
|
25
34
|
// Content that is still loading may have nothing tabbable yet. The
|
|
26
35
|
// content element is focusable itself, so trap focus there until it does.
|
|
27
36
|
fallbackFocus: () => this.content ?? this
|
|
37
|
+
}), this.addEventListener("keydown", (e) => {
|
|
38
|
+
e.key === "Escape" && this.open && !this.focusTrapPaused && !this.focusTrap.paused && !e.defaultPrevented && (e.preventDefault(), e.stopPropagation(), this.close());
|
|
28
39
|
});
|
|
29
40
|
}
|
|
30
41
|
static get observedAttributes() {
|
|
31
42
|
return ["open"];
|
|
32
43
|
}
|
|
33
44
|
connectedCallback() {
|
|
34
|
-
var t, i,
|
|
35
|
-
this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (i = this.content) == null || i.setAttribute("role", "dialog"), (
|
|
36
|
-
r.key === "Escape" && this.open && (r.preventDefault(), r.stopPropagation(), this.close());
|
|
37
|
-
}), this.open && this.wasOpened();
|
|
45
|
+
var t, i, e, r, c, u;
|
|
46
|
+
this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (i = this.content) == null || i.setAttribute("role", "dialog"), (e = this.content) != null && e.hasAttribute("aria-modal") || (r = this.content) == null || r.setAttribute("aria-modal", "true"), (c = this.content) != null && c.hasAttribute("tabindex") || (u = this.content) == null || u.setAttribute("tabindex", "-1"), this.open && this.wasOpened();
|
|
38
47
|
}
|
|
39
48
|
disconnectedCallback() {
|
|
40
49
|
this.connected = !1;
|
|
@@ -51,18 +60,27 @@ const n = class n extends HTMLElement {
|
|
|
51
60
|
const t = new Event("beforeclose", { cancelable: !0 });
|
|
52
61
|
this.dispatchEvent(t) && (this.open = !1);
|
|
53
62
|
}
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Temporarily stop trapping focus and handling Escape, so that another
|
|
65
|
+
* overlay opened from within the modal (e.g. a lightbox mounted in
|
|
66
|
+
* <body>) can manage focus itself.
|
|
67
|
+
*/
|
|
68
|
+
pauseFocusTrap() {
|
|
69
|
+
this.focusTrapPaused = !0, this.focusTrap.pause();
|
|
70
|
+
}
|
|
71
|
+
resumeFocusTrap() {
|
|
72
|
+
this.focusTrapPaused = !1, this.focusTrap.unpause();
|
|
73
|
+
}
|
|
74
|
+
attributeChangedCallback(t, i, e) {
|
|
75
|
+
t !== "open" || !this.connected || (e !== null ? this.wasOpened() : this.wasClosed());
|
|
56
76
|
}
|
|
57
77
|
async wasOpened() {
|
|
58
|
-
document.documentElement.style.overflow = "hidden", this.hidden = !1,
|
|
59
|
-
|
|
60
|
-
return (t = this.focusTrap) == null ? void 0 : t.activate();
|
|
78
|
+
document.documentElement.style.overflow = "hidden", this.hidden = !1, f(this), requestAnimationFrame(() => {
|
|
79
|
+
this.open && (this.focusTrap.activate(), this.focusTrapPaused ? this.focusTrap.pause() : this.focusTrap.unpause());
|
|
61
80
|
}), this.dispatchEvent(new Event("open"));
|
|
62
81
|
}
|
|
63
82
|
wasClosed() {
|
|
64
|
-
|
|
65
|
-
document.documentElement.style.overflow = "", (t = this.focusTrap) == null || t.deactivate(), m(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
|
|
83
|
+
document.documentElement.style.overflow = "", this.focusTrap.deactivate(), this.focusTrapPaused = !1, m(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
|
|
66
84
|
}
|
|
67
85
|
get backdrop() {
|
|
68
86
|
var t;
|
|
@@ -72,7 +90,7 @@ const n = class n extends HTMLElement {
|
|
|
72
90
|
return this.firstElementChild;
|
|
73
91
|
}
|
|
74
92
|
};
|
|
75
|
-
a
|
|
93
|
+
o(a, "attention", (t) => t.animate(
|
|
76
94
|
[
|
|
77
95
|
{ transform: "scale(1)" },
|
|
78
96
|
{ transform: "scale(1.1)" },
|
|
@@ -80,7 +98,7 @@ a(n, "attention", (t) => t.animate(
|
|
|
80
98
|
],
|
|
81
99
|
300
|
|
82
100
|
));
|
|
83
|
-
let
|
|
101
|
+
let h = a;
|
|
84
102
|
export {
|
|
85
|
-
|
|
103
|
+
h as default
|
|
86
104
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default class ModalElement extends HTMLElement {
|
|
2
2
|
static attention: (el: Element) => void;
|
|
3
3
|
static get observedAttributes(): string[];
|
|
4
|
-
private focusTrap
|
|
4
|
+
private focusTrap;
|
|
5
|
+
private focusTrapPaused;
|
|
5
6
|
private connected;
|
|
6
7
|
constructor();
|
|
7
8
|
connectedCallback(): void;
|
|
@@ -9,6 +10,13 @@ export default class ModalElement extends HTMLElement {
|
|
|
9
10
|
get open(): boolean;
|
|
10
11
|
set open(val: boolean);
|
|
11
12
|
close(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Temporarily stop trapping focus and handling Escape, so that another
|
|
15
|
+
* overlay opened from within the modal (e.g. a lightbox mounted in
|
|
16
|
+
* <body>) can manage focus itself.
|
|
17
|
+
*/
|
|
18
|
+
pauseFocusTrap(): void;
|
|
19
|
+
resumeFocusTrap(): void;
|
|
12
20
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
13
21
|
private wasOpened;
|
|
14
22
|
private wasClosed;
|