@y14e/disclosure 2.2.4 → 3.0.0
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.
- package/README.md +4 -4
- package/dist/index.bundle.cjs +98 -137
- package/dist/index.bundle.js +98 -137
- package/dist/index.cjs +21 -33
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -67,36 +67,27 @@ var Disclosure = class _Disclosure {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
this.#rootElement = root;
|
|
70
|
-
this.#settings = resolveOptions(
|
|
71
|
-
resolveOptions(defaults, _Disclosure.defaults),
|
|
72
|
-
options
|
|
73
|
-
);
|
|
70
|
+
this.#settings = resolveOptions(resolveOptions(defaults, _Disclosure.defaults), options);
|
|
74
71
|
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
75
72
|
this.#settings.animation.duration = 0;
|
|
76
73
|
}
|
|
77
74
|
const NOT_NESTED = ":not(:scope summary + * *)";
|
|
78
75
|
this.#detailsElements = [
|
|
79
|
-
...this.#rootElement.querySelectorAll(
|
|
80
|
-
`details${NOT_NESTED}`
|
|
81
|
-
)
|
|
76
|
+
...this.#rootElement.querySelectorAll(`details${NOT_NESTED}`)
|
|
82
77
|
];
|
|
83
78
|
if (!this.#detailsElements.length) {
|
|
84
79
|
console.warn("Missing <details> elements");
|
|
85
80
|
return;
|
|
86
81
|
}
|
|
87
82
|
this.#summaryElements = [
|
|
88
|
-
...this.#rootElement.querySelectorAll(
|
|
89
|
-
`summary${NOT_NESTED}`
|
|
90
|
-
)
|
|
83
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED}`)
|
|
91
84
|
];
|
|
92
85
|
if (!this.#summaryElements.length) {
|
|
93
86
|
console.warn("Missing <summary> elements");
|
|
94
87
|
return;
|
|
95
88
|
}
|
|
96
89
|
this.#contentElements = [
|
|
97
|
-
...this.#rootElement.querySelectorAll(
|
|
98
|
-
`summary${NOT_NESTED} + *`
|
|
99
|
-
)
|
|
90
|
+
...this.#rootElement.querySelectorAll(`summary${NOT_NESTED} + *`)
|
|
100
91
|
];
|
|
101
92
|
if (!this.#contentElements.length) {
|
|
102
93
|
console.warn("Missing content elements");
|
|
@@ -115,11 +106,11 @@ var Disclosure = class _Disclosure {
|
|
|
115
106
|
});
|
|
116
107
|
this.#initialize();
|
|
117
108
|
}
|
|
118
|
-
|
|
109
|
+
close(details) {
|
|
119
110
|
if (this.#isDestroyed) {
|
|
120
111
|
return;
|
|
121
112
|
}
|
|
122
|
-
if (!
|
|
113
|
+
if (!this.#isValidDetails(details)) {
|
|
123
114
|
console.warn("Invalid <details> element");
|
|
124
115
|
return;
|
|
125
116
|
}
|
|
@@ -156,22 +147,18 @@ var Disclosure = class _Disclosure {
|
|
|
156
147
|
this.#contentElements.length = 0;
|
|
157
148
|
this.#rootElement.removeAttribute("data-disclosure-initialized");
|
|
158
149
|
}
|
|
159
|
-
|
|
150
|
+
open(details) {
|
|
160
151
|
if (this.#isDestroyed) {
|
|
161
152
|
return;
|
|
162
153
|
}
|
|
163
|
-
if (!
|
|
154
|
+
if (!this.#isValidDetails(details)) {
|
|
164
155
|
console.warn("Invalid <details> element");
|
|
165
156
|
return;
|
|
166
157
|
}
|
|
167
158
|
this.#toggle(details, true);
|
|
168
159
|
}
|
|
169
160
|
#initialize() {
|
|
170
|
-
saveAttributes(this.#summaryElements, [
|
|
171
|
-
"aria-disabled",
|
|
172
|
-
"style",
|
|
173
|
-
"tabindex"
|
|
174
|
-
]);
|
|
161
|
+
saveAttributes(this.#summaryElements, ["aria-disabled", "style", "tabindex"]);
|
|
175
162
|
this.#eventController = new AbortController();
|
|
176
163
|
const { signal } = this.#eventController;
|
|
177
164
|
this.#detailsElements.forEach((details, i) => {
|
|
@@ -225,22 +212,20 @@ var Disclosure = class _Disclosure {
|
|
|
225
212
|
content.style.removeProperty(name2);
|
|
226
213
|
}
|
|
227
214
|
}
|
|
228
|
-
#toggle(details,
|
|
229
|
-
if (details.hasAttribute("data-disclosure-open") ===
|
|
215
|
+
#toggle(details, isOpen, isProgrammatic = false) {
|
|
216
|
+
if (details.hasAttribute("data-disclosure-open") === isOpen) {
|
|
230
217
|
return;
|
|
231
218
|
}
|
|
232
|
-
if (!
|
|
233
|
-
(d) => d.hasAttribute("data-disclosure-open")
|
|
234
|
-
).length <= 1) {
|
|
219
|
+
if (!isOpen && !isProgrammatic && !this.#settings.collapsible && this.#detailsElements.filter((d) => d.hasAttribute("data-disclosure-open")).length <= 1) {
|
|
235
220
|
return;
|
|
236
221
|
}
|
|
237
222
|
const name = details.getAttribute("data-disclosure-name");
|
|
238
|
-
if (name &&
|
|
223
|
+
if (name && isOpen) {
|
|
239
224
|
details.removeAttribute("name");
|
|
240
|
-
const
|
|
225
|
+
const opened = this.#detailsElements.find(
|
|
241
226
|
(d) => d.hasAttribute("data-disclosure-open") && d.getAttribute("data-disclosure-name") === name
|
|
242
227
|
);
|
|
243
|
-
|
|
228
|
+
opened && this.#toggle(opened, false, true);
|
|
244
229
|
}
|
|
245
230
|
const binding = this.#bindings.get(details);
|
|
246
231
|
if (!binding) {
|
|
@@ -249,12 +234,12 @@ var Disclosure = class _Disclosure {
|
|
|
249
234
|
const { content } = binding;
|
|
250
235
|
const startSize = details.open ? content.offsetHeight : 0;
|
|
251
236
|
binding.animation?.cancel();
|
|
252
|
-
if (
|
|
237
|
+
if (isOpen) {
|
|
253
238
|
details.open = true;
|
|
254
239
|
}
|
|
255
|
-
const endSize =
|
|
240
|
+
const endSize = isOpen ? content.scrollHeight : 0;
|
|
256
241
|
binding.animation?.cancel();
|
|
257
|
-
details.toggleAttribute("data-disclosure-open",
|
|
242
|
+
details.toggleAttribute("data-disclosure-open", isOpen);
|
|
258
243
|
content.style.setProperty("overflow", "clip");
|
|
259
244
|
const { duration, easing } = this.#settings.animation;
|
|
260
245
|
const animation = content.animate(
|
|
@@ -287,6 +272,9 @@ var Disclosure = class _Disclosure {
|
|
|
287
272
|
#isFocusable(element) {
|
|
288
273
|
return element.tabIndex >= 0;
|
|
289
274
|
}
|
|
275
|
+
#isValidDetails(details) {
|
|
276
|
+
return details instanceof HTMLDetailsElement && this.#bindings.has(details);
|
|
277
|
+
}
|
|
290
278
|
async #waitAnimationsFinish() {
|
|
291
279
|
const promises = [];
|
|
292
280
|
for (const content of this.#contentElements) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/disclosure",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@y14e/attribute-utils": "^2.0.18",
|
|
58
|
-
"@y14e/roving-tabindex": "^3.5.
|
|
58
|
+
"@y14e/roving-tabindex": "^3.5.6"
|
|
59
59
|
}
|
|
60
60
|
}
|