@graupl/graupl 1.0.0-alpha.14 → 1.0.0-alpha.16
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/CHANGELOG.md +24 -0
- package/build.js +7 -0
- package/dist/css/base/button.css +2 -0
- package/dist/css/base/button.css.map +1 -0
- package/dist/css/base/form.css.map +1 -0
- package/dist/css/base/link.css.map +1 -0
- package/dist/css/base/table.css.map +1 -0
- package/dist/css/base.css +2 -0
- package/dist/css/base.css.map +1 -0
- package/dist/css/component/accordion.css +2 -0
- package/dist/css/component/accordion.css.map +1 -0
- package/dist/css/component/alert.css +2 -0
- package/dist/css/component/alert.css.map +1 -0
- package/dist/css/component/card.css.map +1 -0
- package/dist/css/component/carousel.css +2 -0
- package/dist/css/component/carousel.css.map +1 -0
- package/dist/css/component/input-group.css.map +1 -0
- package/dist/css/component/menu.css.map +1 -0
- package/dist/css/component/navigation.css.map +1 -0
- package/dist/css/component.css +2 -0
- package/dist/css/component.css.map +1 -0
- package/dist/css/graupl.css +2 -0
- package/dist/css/graupl.css.map +1 -0
- package/dist/css/init.css.map +1 -0
- package/dist/css/layout/columns.css.map +1 -0
- package/dist/css/layout/container.css.map +1 -0
- package/dist/css/layout/flex-columns.css.map +1 -0
- package/dist/css/layout.css +2 -0
- package/dist/css/layout.css.map +1 -0
- package/dist/css/normalize.css.map +1 -0
- package/dist/css/state/focus.css +2 -0
- package/dist/css/state/focus.css.map +1 -0
- package/dist/css/state.css +2 -0
- package/dist/css/state.css.map +1 -0
- package/dist/css/theme/color.css.map +1 -0
- package/dist/css/theme/typography.css.map +1 -0
- package/dist/css/theme.css.map +1 -0
- package/dist/css/utilities/alignment.css.map +1 -0
- package/dist/css/utilities/color.css.map +1 -0
- package/dist/css/utilities/display.css.map +1 -0
- package/dist/css/utilities/flex.css.map +1 -0
- package/dist/css/utilities/height.css.map +1 -0
- package/dist/css/utilities/inset.css.map +1 -0
- package/dist/css/utilities/justification.css.map +1 -0
- package/dist/css/utilities/list.css.map +1 -0
- package/dist/css/utilities/order.css.map +1 -0
- package/dist/css/utilities/postion.css.map +1 -0
- package/dist/css/utilities/spacing.css.map +1 -0
- package/dist/css/utilities/typography.css.map +1 -0
- package/dist/css/utilities/visibility.css.map +1 -0
- package/dist/css/utilities/width.css.map +1 -0
- package/dist/css/utilities.css.map +1 -0
- package/dist/js/component/accordion.cjs.js +3 -0
- package/dist/js/component/accordion.esm.js +1289 -0
- package/dist/js/component/accordion.iife.js +3 -0
- package/dist/js/component/alert.cjs.js +3 -0
- package/dist/js/component/alert.esm.js +529 -0
- package/dist/js/component/alert.iife.js +3 -0
- package/dist/js/component/carousel.cjs.js +3 -0
- package/dist/js/component/carousel.esm.js +1110 -0
- package/dist/js/component/carousel.iife.js +3 -0
- package/dist/js/graupl.cjs.js +5 -0
- package/dist/js/graupl.esm.js +1462 -0
- package/dist/js/graupl.iife.js +5 -0
- package/index.html +56 -2
- package/index.js +12 -0
- package/package.json +26 -5
- package/scss/component/accordion.scss +3 -0
- package/src/js/accordion/Accordion.js +1163 -0
- package/src/js/accordion/AccordionItem.js +496 -0
- package/src/js/accordion/index.js +10 -0
- package/src/js/alert/Alert.js +71 -1
- package/src/js/alert/index.js +1 -11
- package/src/js/carousel/Carousel.js +67 -16
- package/src/js/carousel/index.js +1 -11
- package/src/js/eventHandlers.js +7 -0
- package/src/js/storage.js +106 -0
- package/src/scss/_defaults.scss +29 -0
- package/src/scss/base/button/_mixins.scss +64 -62
- package/src/scss/component/_index.scss +1 -0
- package/src/scss/component/accordion/_defaults.scss +40 -0
- package/src/scss/component/accordion/_index.scss +180 -0
- package/src/scss/component/accordion/_variables.scss +304 -0
- package/src/scss/component/carousel/_index.scss +6 -0
- package/src/scss/layout/columns/_index.scss +1 -1
- package/src/scss/layout/flex-columns/_index.scss +1 -1
- package/src/scss/state/focus/_index.scss +6 -6
- package/src/scss/state/focus/_mixins.scss +15 -0
- package/stylelint.config.js +4 -0
- package/vite.config.js +57 -0
- package/dist/base/button.css +0 -2
- package/dist/base/button.css.map +0 -1
- package/dist/base/form.css.map +0 -1
- package/dist/base/link.css.map +0 -1
- package/dist/base/table.css.map +0 -1
- package/dist/base.css +0 -2
- package/dist/base.css.map +0 -1
- package/dist/component/alert.css +0 -2
- package/dist/component/alert.css.map +0 -1
- package/dist/component/card.css.map +0 -1
- package/dist/component/carousel.css +0 -2
- package/dist/component/carousel.css.map +0 -1
- package/dist/component/input-group.css.map +0 -1
- package/dist/component/menu.css.map +0 -1
- package/dist/component/navigation.css.map +0 -1
- package/dist/component.css +0 -2
- package/dist/component.css.map +0 -1
- package/dist/graupl.css +0 -2
- package/dist/graupl.css.map +0 -1
- package/dist/init.css.map +0 -1
- package/dist/layout/columns.css.map +0 -1
- package/dist/layout/container.css.map +0 -1
- package/dist/layout/flex-columns.css.map +0 -1
- package/dist/layout.css +0 -2
- package/dist/layout.css.map +0 -1
- package/dist/normalize.css.map +0 -1
- package/dist/state/focus.css +0 -2
- package/dist/state/focus.css.map +0 -1
- package/dist/state.css +0 -2
- package/dist/state.css.map +0 -1
- package/dist/theme/color.css.map +0 -1
- package/dist/theme/typography.css.map +0 -1
- package/dist/theme.css.map +0 -1
- package/dist/utilities/alignment.css.map +0 -1
- package/dist/utilities/color.css.map +0 -1
- package/dist/utilities/display.css.map +0 -1
- package/dist/utilities/flex.css.map +0 -1
- package/dist/utilities/height.css.map +0 -1
- package/dist/utilities/inset.css.map +0 -1
- package/dist/utilities/justification.css.map +0 -1
- package/dist/utilities/list.css.map +0 -1
- package/dist/utilities/order.css.map +0 -1
- package/dist/utilities/postion.css.map +0 -1
- package/dist/utilities/spacing.css.map +0 -1
- package/dist/utilities/typography.css.map +0 -1
- package/dist/utilities/visibility.css.map +0 -1
- package/dist/utilities/width.css.map +0 -1
- package/dist/utilities.css.map +0 -1
- /package/dist/{base → css/base}/form.css +0 -0
- /package/dist/{base → css/base}/link.css +0 -0
- /package/dist/{base → css/base}/table.css +0 -0
- /package/dist/{component → css/component}/card.css +0 -0
- /package/dist/{component → css/component}/input-group.css +0 -0
- /package/dist/{component → css/component}/menu.css +0 -0
- /package/dist/{component → css/component}/navigation.css +0 -0
- /package/dist/{init.css → css/init.css} +0 -0
- /package/dist/{layout → css/layout}/columns.css +0 -0
- /package/dist/{layout → css/layout}/container.css +0 -0
- /package/dist/{layout → css/layout}/flex-columns.css +0 -0
- /package/dist/{normalize.css → css/normalize.css} +0 -0
- /package/dist/{theme → css/theme}/color.css +0 -0
- /package/dist/{theme → css/theme}/typography.css +0 -0
- /package/dist/{theme.css → css/theme.css} +0 -0
- /package/dist/{utilities → css/utilities}/alignment.css +0 -0
- /package/dist/{utilities → css/utilities}/color.css +0 -0
- /package/dist/{utilities → css/utilities}/display.css +0 -0
- /package/dist/{utilities → css/utilities}/flex.css +0 -0
- /package/dist/{utilities → css/utilities}/height.css +0 -0
- /package/dist/{utilities → css/utilities}/inset.css +0 -0
- /package/dist/{utilities → css/utilities}/justification.css +0 -0
- /package/dist/{utilities → css/utilities}/list.css +0 -0
- /package/dist/{utilities → css/utilities}/order.css +0 -0
- /package/dist/{utilities → css/utilities}/postion.css +0 -0
- /package/dist/{utilities → css/utilities}/spacing.css +0 -0
- /package/dist/{utilities → css/utilities}/typography.css +0 -0
- /package/dist/{utilities → css/utilities}/visibility.css +0 -0
- /package/dist/{utilities → css/utilities}/width.css +0 -0
- /package/dist/{utilities.css → css/utilities.css} +0 -0
|
@@ -0,0 +1,1289 @@
|
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var M = (e, t, i) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var r = (e, t, i) => M(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
function g(e, t) {
|
|
5
|
+
try {
|
|
6
|
+
if (typeof t != "object") {
|
|
7
|
+
const i = typeof t;
|
|
8
|
+
throw new TypeError(
|
|
9
|
+
`Elements given to isValidInstance() must be inside of an object. "${i}" given.`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
for (const i in t)
|
|
13
|
+
if (!(t[i] instanceof e)) {
|
|
14
|
+
const o = typeof t[i];
|
|
15
|
+
throw new TypeError(
|
|
16
|
+
`${i} must be an instance of ${e.name}. "${o}" given.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
status: !0,
|
|
21
|
+
error: null
|
|
22
|
+
};
|
|
23
|
+
} catch (i) {
|
|
24
|
+
return {
|
|
25
|
+
status: !1,
|
|
26
|
+
error: i
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function s(e, t) {
|
|
31
|
+
try {
|
|
32
|
+
if (typeof t != "object") {
|
|
33
|
+
const i = typeof t;
|
|
34
|
+
throw new TypeError(
|
|
35
|
+
`Values given to isValidType() must be inside of an object. "${i}" given.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
for (const i in t) {
|
|
39
|
+
const o = typeof t[i];
|
|
40
|
+
if (o !== e)
|
|
41
|
+
throw new TypeError(`${i} must be a ${e}. "${o}" given.`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
status: !0,
|
|
45
|
+
error: null
|
|
46
|
+
};
|
|
47
|
+
} catch (i) {
|
|
48
|
+
return {
|
|
49
|
+
status: !1,
|
|
50
|
+
error: i
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function E(e) {
|
|
55
|
+
try {
|
|
56
|
+
if (typeof e != "object") {
|
|
57
|
+
const t = typeof e;
|
|
58
|
+
throw new TypeError(
|
|
59
|
+
`Values given to isQuerySelector() must be inside of an object. "${t}" given.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
for (const t in e)
|
|
63
|
+
try {
|
|
64
|
+
if (e[t] === null)
|
|
65
|
+
throw new Error();
|
|
66
|
+
document.querySelector(e[t]);
|
|
67
|
+
} catch {
|
|
68
|
+
throw new TypeError(
|
|
69
|
+
`${t} must be a valid query selector. "${e[t]}" given.`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
status: !0,
|
|
74
|
+
error: null
|
|
75
|
+
};
|
|
76
|
+
} catch (t) {
|
|
77
|
+
return {
|
|
78
|
+
status: !1,
|
|
79
|
+
error: t
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function u(e) {
|
|
84
|
+
try {
|
|
85
|
+
if (typeof e != "object" || Array.isArray(e)) {
|
|
86
|
+
const t = typeof e;
|
|
87
|
+
throw new TypeError(
|
|
88
|
+
`Values given to isValidClassList() must be inside of an object. "${t}" given.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
for (const t in e) {
|
|
92
|
+
const i = typeof e[t];
|
|
93
|
+
if (i !== "string")
|
|
94
|
+
if (Array.isArray(e[t]))
|
|
95
|
+
e[t].forEach((o) => {
|
|
96
|
+
if (typeof o != "string")
|
|
97
|
+
throw new TypeError(
|
|
98
|
+
`${t} must be a string or an array of strings. An array containing non-strings given.`
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
else
|
|
102
|
+
throw new TypeError(
|
|
103
|
+
`${t} must be a string or an array of strings. "${i}" given.`
|
|
104
|
+
);
|
|
105
|
+
else {
|
|
106
|
+
const o = {};
|
|
107
|
+
o[t] = e[t], E(o);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
status: !0,
|
|
112
|
+
error: null
|
|
113
|
+
};
|
|
114
|
+
} catch (t) {
|
|
115
|
+
return {
|
|
116
|
+
status: !1,
|
|
117
|
+
error: t
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function _(e, t) {
|
|
122
|
+
if (s("string", { tagName: e }).status && g(HTMLElement, t).status) {
|
|
123
|
+
const i = e.toLowerCase();
|
|
124
|
+
let o = !0;
|
|
125
|
+
for (const n in t)
|
|
126
|
+
t[n].tagName.toLowerCase() !== i && (o = !1);
|
|
127
|
+
return o;
|
|
128
|
+
} else
|
|
129
|
+
return !1;
|
|
130
|
+
}
|
|
131
|
+
function m(e, t) {
|
|
132
|
+
e === "" || e.length === 0 || (typeof e == "string" ? t.classList.add(e) : t.classList.add(...e));
|
|
133
|
+
}
|
|
134
|
+
function p(e, t) {
|
|
135
|
+
e === "" || e.length === 0 || (typeof e == "string" ? t.classList.remove(e) : t.classList.remove(...e));
|
|
136
|
+
}
|
|
137
|
+
class C {
|
|
138
|
+
/**
|
|
139
|
+
* Constructs a new Accordion item object.
|
|
140
|
+
*
|
|
141
|
+
* @class
|
|
142
|
+
*
|
|
143
|
+
* @param {object} options - The options object.
|
|
144
|
+
* @param {HTMLElement} options.accordionItemElement - The accordion item element.
|
|
145
|
+
* @param {HTMLElement} options.accordionItemToggleElement - The toggle element.
|
|
146
|
+
* @param {HTMLElement} options.accordionItemHeaderElement - The header element.
|
|
147
|
+
* @param {HTMLElement} options.accordionItemContentElement - The content element.
|
|
148
|
+
* @param {Accordion} [options.parentAccordion = null] - The accordion containing this item.
|
|
149
|
+
*/
|
|
150
|
+
constructor({
|
|
151
|
+
accordionItemElement: t,
|
|
152
|
+
accordionItemToggleElement: i,
|
|
153
|
+
accordionItemHeaderElement: o,
|
|
154
|
+
accordionItemContentElement: n,
|
|
155
|
+
parentAccordion: a = null
|
|
156
|
+
}) {
|
|
157
|
+
/**
|
|
158
|
+
* The HTML elements for the accordion item in the DOM.
|
|
159
|
+
*
|
|
160
|
+
* @protected
|
|
161
|
+
*
|
|
162
|
+
* @type {Object<HTMLElement>}
|
|
163
|
+
*
|
|
164
|
+
* @property {HTMLElement} item - The accordion item element.
|
|
165
|
+
* @property {HTMLElement} toggle - The controller element.
|
|
166
|
+
* @property {HTMLElement} header - The header element.
|
|
167
|
+
* @property {HTMLElement} content - The content element.
|
|
168
|
+
*/
|
|
169
|
+
r(this, "_dom", {
|
|
170
|
+
item: null,
|
|
171
|
+
toggle: null,
|
|
172
|
+
header: null,
|
|
173
|
+
content: null
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* The declared graupl accordion elements within the accordion item.
|
|
177
|
+
*
|
|
178
|
+
* @protected
|
|
179
|
+
*
|
|
180
|
+
* @type {Object<Accordion>}
|
|
181
|
+
*
|
|
182
|
+
* @property {Accordion} parentAccordion - The parent accordion containing this item.
|
|
183
|
+
*/
|
|
184
|
+
r(this, "_elements", {
|
|
185
|
+
parentAccordion: null
|
|
186
|
+
});
|
|
187
|
+
/**
|
|
188
|
+
* The open state of the accordion.
|
|
189
|
+
*
|
|
190
|
+
* @protected
|
|
191
|
+
*
|
|
192
|
+
* @type {boolean}
|
|
193
|
+
*/
|
|
194
|
+
r(this, "_open", !1);
|
|
195
|
+
/**
|
|
196
|
+
* The locked state of the accordions item.
|
|
197
|
+
*
|
|
198
|
+
* If locked, the accordion item cannot be closed.
|
|
199
|
+
*
|
|
200
|
+
* @protected
|
|
201
|
+
*
|
|
202
|
+
* @type {boolean}
|
|
203
|
+
*/
|
|
204
|
+
r(this, "_locked", !1);
|
|
205
|
+
/**
|
|
206
|
+
* The event that is triggered when the accordion item is shown.
|
|
207
|
+
*
|
|
208
|
+
* @protected
|
|
209
|
+
*
|
|
210
|
+
* @event grauplAccordionItemExpand
|
|
211
|
+
*
|
|
212
|
+
* @type {CustomEvent}
|
|
213
|
+
*
|
|
214
|
+
* @property {boolean} bubbles - A flag to bubble the event.
|
|
215
|
+
* @property {Object<AccordionItem>} detail - The details object containing the Accordion item itself.
|
|
216
|
+
*/
|
|
217
|
+
r(this, "_expandEvent", new CustomEvent("grauplAccordionItemExpand", {
|
|
218
|
+
bubbles: !0,
|
|
219
|
+
detail: { item: this }
|
|
220
|
+
}));
|
|
221
|
+
/**
|
|
222
|
+
* The event that is triggered when the accordion item is hidden.
|
|
223
|
+
*
|
|
224
|
+
* @protected
|
|
225
|
+
*
|
|
226
|
+
* @event grauplAccordionItemCollapse
|
|
227
|
+
*
|
|
228
|
+
* @type {CustomEvent}
|
|
229
|
+
*
|
|
230
|
+
* @property {boolean} bubbles - A flag to bubble the event.
|
|
231
|
+
* @property {Object<AccordionItem>} detail - The details object containing the Accordion item itself.
|
|
232
|
+
*/
|
|
233
|
+
r(this, "_collapseEvent", new CustomEvent("grauplAccordionItemCollapse", {
|
|
234
|
+
bubbles: !0,
|
|
235
|
+
detail: { item: this }
|
|
236
|
+
}));
|
|
237
|
+
this._dom.item = t, this._dom.toggle = i, this._dom.header = o, this._dom.content = n, this._elements.parentAccordion = a;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Initializes the accordion item.
|
|
241
|
+
*/
|
|
242
|
+
initialize() {
|
|
243
|
+
this._setIds(), this._setAriaAttributes(), this.dom.toggle.getAttribute("aria-expanded") === "true" ? this.show(!1, !1) : this.hide(!1, !1);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The HTML elements for the accordion item in the DOM.
|
|
247
|
+
*
|
|
248
|
+
* @readonly
|
|
249
|
+
*
|
|
250
|
+
* @type {object}
|
|
251
|
+
*
|
|
252
|
+
* @see _dom
|
|
253
|
+
*/
|
|
254
|
+
get dom() {
|
|
255
|
+
return this._dom;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* The declared graupl accordion elements within the accordion item.
|
|
259
|
+
*
|
|
260
|
+
* @readonly
|
|
261
|
+
*
|
|
262
|
+
* @type {Object<Accordion>}
|
|
263
|
+
*
|
|
264
|
+
* @see _elements
|
|
265
|
+
*/
|
|
266
|
+
get elements() {
|
|
267
|
+
return this._elements;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The open state of the accordion.
|
|
271
|
+
*
|
|
272
|
+
* @readonly
|
|
273
|
+
*
|
|
274
|
+
* @type {object}
|
|
275
|
+
*
|
|
276
|
+
* @see _open
|
|
277
|
+
*/
|
|
278
|
+
get isOpen() {
|
|
279
|
+
return this._open;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The locked state of the accordions item.
|
|
283
|
+
*
|
|
284
|
+
* If locked, the accordion item cannot be closed.
|
|
285
|
+
*
|
|
286
|
+
* @readonly
|
|
287
|
+
*
|
|
288
|
+
* @type {boolean}
|
|
289
|
+
*
|
|
290
|
+
* @see _locked
|
|
291
|
+
*/
|
|
292
|
+
get isLocked() {
|
|
293
|
+
return this._locked;
|
|
294
|
+
}
|
|
295
|
+
set isOpen(t) {
|
|
296
|
+
s("boolean", { value: t }), this._open !== t && (this._open = t);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Sets the IDs for the accordion item and it's elements if they don't exist.
|
|
300
|
+
*
|
|
301
|
+
* The generated IDs use the parent accordion's key and follows the pattern:
|
|
302
|
+
* - Accordion item: `accordion-item-{key}-{index}`
|
|
303
|
+
* - Accordion item toggle: `accordion-item-toggle-{key}-{index}`
|
|
304
|
+
* - Accordion item content: `accordion-item-content-{key}-{index}`
|
|
305
|
+
*/
|
|
306
|
+
_setIds() {
|
|
307
|
+
const { key: t } = this.elements.parentAccordion, i = this.elements.parentAccordion.dom.accordionItems.indexOf(
|
|
308
|
+
this.dom.item
|
|
309
|
+
);
|
|
310
|
+
this.dom.item.id = this.dom.item.id || `accordion-item-${t}-${i}`, this.dom.toggle.id = this.dom.toggle.id || `accordion-item-toggle-${t}-${i}`, this.dom.header.id = this.dom.header.id || `accordion-item-header-${t}-${i}`, this.dom.content.id = this.dom.content.id || `accordion-item-content-${t}-${i}`;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Sets the ARIA attributes for the accordion item and it's elements.
|
|
314
|
+
*/
|
|
315
|
+
_setAriaAttributes() {
|
|
316
|
+
_("button", { toggle: this.dom.toggle }) || this.dom.toggle.setAttribute("role", "button"), this.dom.toggle.getAttribute("aria-expanded") !== "true" && this.dom.toggle.setAttribute("aria-expanded", "false"), this.dom.toggle.setAttribute("aria-controls", this.dom.content.id), _("section", { content: this.dom.content }) || this.dom.content.setAttribute("role", "region"), this.dom.content.setAttribute("aria-labelledby", this.dom.toggle.id);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Shows the accordion item.
|
|
320
|
+
*
|
|
321
|
+
* @public
|
|
322
|
+
*
|
|
323
|
+
* @fires grauplAccordionItemExpand
|
|
324
|
+
*
|
|
325
|
+
* @param {boolean} [emit = true] - Emit the show event once shown.
|
|
326
|
+
* @param {boolean} [transition = true] - Respect the transition class.
|
|
327
|
+
*/
|
|
328
|
+
show(t = !0, i = !0) {
|
|
329
|
+
if (this._open)
|
|
330
|
+
return;
|
|
331
|
+
const { closeClass: o, openClass: n, transitionClass: a, openDuration: l } = this.elements.parentAccordion;
|
|
332
|
+
this.dom.toggle.setAttribute("aria-expanded", "true"), i && a !== "" ? (m(a, this.dom.item), requestAnimationFrame(() => {
|
|
333
|
+
p(o, this.dom.item), this.dom.item.style.height = `${this.dom.header.getBoundingClientRect().height}px`, requestAnimationFrame(() => {
|
|
334
|
+
m(n, this.dom.item), this.dom.item.style.height = `${this.dom.header.getBoundingClientRect().height + this.dom.content.getBoundingClientRect().height}px`, requestAnimationFrame(() => {
|
|
335
|
+
setTimeout(() => {
|
|
336
|
+
p(a, this.dom.item), this.dom.item.style.height = "";
|
|
337
|
+
}, l);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
})) : (m(n, this.dom.item), p(o, this.dom.item)), this._open = !0, this.elements.parentAccordion.allowMultipleExpand || (this.unlockSiblings(), this.closeSiblings()), this.elements.parentAccordion.allowNoExpand || (this.elements.parentAccordion.openAccordionItems.length <= 1 ? this.lock() : this.unlockSiblings()), t && this.dom.item.dispatchEvent(this._expandEvent);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Hides the accordion item.
|
|
344
|
+
*
|
|
345
|
+
* @public
|
|
346
|
+
*
|
|
347
|
+
* @fires grauplAccordionItemCollapse
|
|
348
|
+
*
|
|
349
|
+
* @param {boolean} [emit = true] - Emit the show event once shown.
|
|
350
|
+
* @param {boolean} [transition = true] - Respect the transition class.
|
|
351
|
+
*/
|
|
352
|
+
hide(t = !0, i = !0) {
|
|
353
|
+
if (!this._open || !this.elements.parentAccordion.allowNoExpand && this.elements.parentAccordion.openAccordionItems.length <= 1)
|
|
354
|
+
return;
|
|
355
|
+
const { closeClass: o, openClass: n, transitionClass: a, closeDuration: l } = this.elements.parentAccordion;
|
|
356
|
+
this.dom.toggle.setAttribute("aria-expanded", "false"), i && a !== "" ? (m(a, this.dom.item), this.dom.item.style.height = `${this.dom.item.getBoundingClientRect().height}px`, requestAnimationFrame(() => {
|
|
357
|
+
p(n, this.dom.item), this.dom.item.style.height = `${this.dom.header.getBoundingClientRect().height}px`, requestAnimationFrame(() => {
|
|
358
|
+
m(o, this.dom.item), requestAnimationFrame(() => {
|
|
359
|
+
setTimeout(() => {
|
|
360
|
+
p(a, this.dom.item), this.dom.item.style.height = "";
|
|
361
|
+
}, l);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
})) : (m(o, this.dom.item), p(n, this.dom.item)), this._open = !1, !this.elements.parentAccordion.allowNoExpand && this.elements.parentAccordion.openAccordionItems.length === 1 && this.elements.parentAccordion.openAccordionItems[0].lock(), t && this.dom.item.dispatchEvent(this._collapseEvent);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Toggle the accordion item.
|
|
368
|
+
*
|
|
369
|
+
* @public
|
|
370
|
+
*/
|
|
371
|
+
toggle() {
|
|
372
|
+
this.isOpen ? this.hide() : this.show();
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Focuses the accordion item.
|
|
376
|
+
*
|
|
377
|
+
* @public
|
|
378
|
+
*/
|
|
379
|
+
focus() {
|
|
380
|
+
this.dom.toggle.focus();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Blurs the accordion item.
|
|
384
|
+
*
|
|
385
|
+
* @public
|
|
386
|
+
*/
|
|
387
|
+
blur() {
|
|
388
|
+
this.dom.toggle.blur();
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Locks the accordion item.
|
|
392
|
+
*
|
|
393
|
+
* @public
|
|
394
|
+
*/
|
|
395
|
+
lock() {
|
|
396
|
+
this._locked = !0, this.dom.toggle.setAttribute("disabled", "true");
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Unlocks the accordion item.
|
|
400
|
+
*
|
|
401
|
+
* @public
|
|
402
|
+
*/
|
|
403
|
+
unlock() {
|
|
404
|
+
this._locked = !1, this.dom.toggle.removeAttribute("disabled");
|
|
405
|
+
}
|
|
406
|
+
closeSiblings() {
|
|
407
|
+
this.elements.parentAccordion && this.elements.parentAccordion.elements.accordionItems.forEach((t) => {
|
|
408
|
+
t !== this && t.hide();
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Unlocks the siblings of the accordion item.
|
|
413
|
+
*
|
|
414
|
+
* @public
|
|
415
|
+
*/
|
|
416
|
+
unlockSiblings() {
|
|
417
|
+
this.elements.parentAccordion && this.elements.parentAccordion.elements.accordionItems.forEach((t) => {
|
|
418
|
+
t !== this && t.unlock();
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function w(e) {
|
|
423
|
+
try {
|
|
424
|
+
const t = e.key || e.keyCode, i = {
|
|
425
|
+
Enter: t === "Enter" || t === 13,
|
|
426
|
+
Space: t === " " || t === "Spacebar" || t === 32,
|
|
427
|
+
Escape: t === "Escape" || t === "Esc" || t === 27,
|
|
428
|
+
ArrowUp: t === "ArrowUp" || t === "Up" || t === 38,
|
|
429
|
+
ArrowRight: t === "ArrowRight" || t === "Right" || t === 39,
|
|
430
|
+
ArrowDown: t === "ArrowDown" || t === "Down" || t === 40,
|
|
431
|
+
ArrowLeft: t === "ArrowLeft" || t === "Left" || t === 37,
|
|
432
|
+
Home: t === "Home" || t === 36,
|
|
433
|
+
End: t === "End" || t === 35,
|
|
434
|
+
Tab: t === "Tab" || t === 9
|
|
435
|
+
};
|
|
436
|
+
return Object.keys(i).find((o) => i[o] === !0) || "";
|
|
437
|
+
} catch {
|
|
438
|
+
return "";
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function h(e) {
|
|
442
|
+
e.preventDefault(), e.stopPropagation();
|
|
443
|
+
}
|
|
444
|
+
function L(e = null) {
|
|
445
|
+
window.Graupl = window.Graupl || {}, s("string", { type: e }) && (window.Graupl[e] = window.Graupl[e] || {});
|
|
446
|
+
}
|
|
447
|
+
function K(e = null) {
|
|
448
|
+
return s("string", { type: e }) ? window.Graupl[e] : window.Graupl;
|
|
449
|
+
}
|
|
450
|
+
function O(e, t = {}) {
|
|
451
|
+
s("string", { type: e }) && s("object", { data: t }) && (window.Graupl[e] = t);
|
|
452
|
+
}
|
|
453
|
+
function G(e) {
|
|
454
|
+
s("string", { type: e }) && (window.Graupl[e] = {});
|
|
455
|
+
}
|
|
456
|
+
function H(e, t, i) {
|
|
457
|
+
s("string", { type: e, key: t }) && (window.Graupl[e][t] = i);
|
|
458
|
+
}
|
|
459
|
+
function j(e, t) {
|
|
460
|
+
return s("string", { type: e, key: t }) ? window.Graupl[e][t] : null;
|
|
461
|
+
}
|
|
462
|
+
function F(e, t) {
|
|
463
|
+
s("string", { type: e, key: t }) && delete window.Graupl[e][t];
|
|
464
|
+
}
|
|
465
|
+
const y = {
|
|
466
|
+
initializeStorage: L,
|
|
467
|
+
getStorage: K,
|
|
468
|
+
setStorage: O,
|
|
469
|
+
clearStorage: G,
|
|
470
|
+
pushToStorage: H,
|
|
471
|
+
getFromStorage: j,
|
|
472
|
+
removeFromStorage: F
|
|
473
|
+
};
|
|
474
|
+
class V {
|
|
475
|
+
/**
|
|
476
|
+
* Constructs a new `Accordion`.
|
|
477
|
+
*
|
|
478
|
+
* @param {object} options - The options for generating the accordion.
|
|
479
|
+
* @param {HTMLElement} [options.accordionElement] - The accordion element in the DOM.
|
|
480
|
+
* @param {string} [options.accordionItemSelector = .accordion-item] - The query selector string for accordion items.
|
|
481
|
+
* @param {string} [options.accordionItemToggleSelector = .accordion-item-toggle] - The query selector string for accordion toggle.
|
|
482
|
+
* @param {string} [options.accordionItemHeaderSelector = .accordion-item-header] - The query selector string for accordion header.
|
|
483
|
+
* @param {string} [options.accordionItemContentSelector = .accordion-item-content] - The query selector string for accordion content.
|
|
484
|
+
* @param {?(string|string[])} [options.openClass = show] - The class to apply when a accordion is "open".
|
|
485
|
+
* @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a accordion is "closed".
|
|
486
|
+
* @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a accordion is transitioning between "open" and "closed" states.
|
|
487
|
+
* @param {number} [options.transitionDuration = 300] - The duration of the transition between "open" and "closed" states (in milliseconds).
|
|
488
|
+
* @param {number} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds).
|
|
489
|
+
* @param {number} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds).
|
|
490
|
+
* @param {boolean} [options.optionalKeySupport = false] - A flag to determine if accordions can be navigated with arrows.
|
|
491
|
+
* @param {boolean} [options.allowMultipleExpand = true] - A flag to determine if multiple accordions can be open at the same time.
|
|
492
|
+
* @param {boolean} [options.allowNoExpand = true] - A flag to determine if no accordions can be open at the same time.
|
|
493
|
+
* @param {?string} [options.prefix = graupl-] - The prefix to use for CSS custom properties.
|
|
494
|
+
* @param {?string} [options.key = null] - The key used to generate IDs throughout the accordion.
|
|
495
|
+
* @param {boolean} [options.initialize = false] - A flag to initialize the accordion immediately upon creation.
|
|
496
|
+
*/
|
|
497
|
+
constructor({
|
|
498
|
+
accordionElement: t,
|
|
499
|
+
accordionItemSelector: i = ".accordion-item",
|
|
500
|
+
accordionItemToggleSelector: o = ".accordion-item-toggle",
|
|
501
|
+
accordionItemHeaderSelector: n = ".accordion-item-header",
|
|
502
|
+
accordionItemContentSelector: a = ".accordion-item-content",
|
|
503
|
+
openClass: l = "show",
|
|
504
|
+
closeClass: d = "hide",
|
|
505
|
+
transitionClass: f = "transitioning",
|
|
506
|
+
transitionDuration: c = 300,
|
|
507
|
+
openDuration: b = -1,
|
|
508
|
+
closeDuration: A = -1,
|
|
509
|
+
optionalKeySupport: I = !1,
|
|
510
|
+
allowMultipleExpand: k = !0,
|
|
511
|
+
allowNoExpand: D = !0,
|
|
512
|
+
prefix: x = "am-",
|
|
513
|
+
key: $ = null,
|
|
514
|
+
initialize: T = !1
|
|
515
|
+
}) {
|
|
516
|
+
/**
|
|
517
|
+
* The DOM elements within the accordion.
|
|
518
|
+
*
|
|
519
|
+
* @protected
|
|
520
|
+
*
|
|
521
|
+
* @type {Object<HTMLElement, HTMLElement[]>}
|
|
522
|
+
*
|
|
523
|
+
* @property {HTMLElement} accordion - The accordion element.
|
|
524
|
+
* @property {HTMLElement[]} accordionItems - An array of accordion items.
|
|
525
|
+
* @property {HTMLElement[]} accordionItemToggles - An array of accordion item toggles.
|
|
526
|
+
* @property {HTMLElement[]} accordionItemHeaders - An array of accordion headers.
|
|
527
|
+
* @property {HTMLElement[]} accordionItemContents - An array of accordion item contents.
|
|
528
|
+
*/
|
|
529
|
+
r(this, "_dom", {
|
|
530
|
+
accordion: null,
|
|
531
|
+
accordionItems: [],
|
|
532
|
+
accordionItemToggles: [],
|
|
533
|
+
accordionItemHeaders: [],
|
|
534
|
+
accordionItemContents: []
|
|
535
|
+
});
|
|
536
|
+
/**
|
|
537
|
+
* The DOM elements within the accordion that cannot be reset or generated by the accordion.
|
|
538
|
+
*
|
|
539
|
+
* @protected
|
|
540
|
+
*
|
|
541
|
+
* @type {string[]}
|
|
542
|
+
*/
|
|
543
|
+
r(this, "_domLock", ["accordion"]);
|
|
544
|
+
/**
|
|
545
|
+
* The query selectors used by the accordion.
|
|
546
|
+
*
|
|
547
|
+
* @protected
|
|
548
|
+
*
|
|
549
|
+
* @type {Object<string>}
|
|
550
|
+
*
|
|
551
|
+
* @property {string} accordionItems - The query selector for accordion items.
|
|
552
|
+
* @property {string} accordionItemToggles - The query selector for accordion toggles.
|
|
553
|
+
* @property {string} accordionItemHeaders - The query selector for accordion headers.
|
|
554
|
+
* @property {string} accordionItemContents - The query selector for accordion contents.
|
|
555
|
+
*/
|
|
556
|
+
r(this, "_selectors", {
|
|
557
|
+
accordionItems: "",
|
|
558
|
+
accordionItemToggles: "",
|
|
559
|
+
accordionItemHeaders: "",
|
|
560
|
+
accordionItemContents: ""
|
|
561
|
+
});
|
|
562
|
+
/**
|
|
563
|
+
* The list of accordion items.
|
|
564
|
+
*
|
|
565
|
+
* @protected
|
|
566
|
+
*
|
|
567
|
+
* @type {Object<AccordionItem[]>}
|
|
568
|
+
*
|
|
569
|
+
* @property {AccordionItem[]} accordionItems - The list of accordion items.
|
|
570
|
+
*/
|
|
571
|
+
r(this, "_elements", {
|
|
572
|
+
accordionItems: []
|
|
573
|
+
});
|
|
574
|
+
/**
|
|
575
|
+
* The class(es) to apply when the accordion is open.
|
|
576
|
+
*
|
|
577
|
+
* @protected
|
|
578
|
+
*
|
|
579
|
+
* @type {string|string[]}
|
|
580
|
+
*/
|
|
581
|
+
r(this, "_openClass", "show");
|
|
582
|
+
/**
|
|
583
|
+
* The class(es) to apply when the accordion is closed.
|
|
584
|
+
*
|
|
585
|
+
* @protected
|
|
586
|
+
*
|
|
587
|
+
* @type {string|string[]}
|
|
588
|
+
*/
|
|
589
|
+
r(this, "_closeClass", "hide");
|
|
590
|
+
/**
|
|
591
|
+
* The class(es) to apply when the accordion is transitioning between states.
|
|
592
|
+
*
|
|
593
|
+
* @protected
|
|
594
|
+
*
|
|
595
|
+
* @type {string|string[]}
|
|
596
|
+
*/
|
|
597
|
+
r(this, "_transitionClass", "transitioning");
|
|
598
|
+
/**
|
|
599
|
+
* The duration time (in milliseconds) for the transition between open and closed states.
|
|
600
|
+
*
|
|
601
|
+
* @protected
|
|
602
|
+
*
|
|
603
|
+
* @type {number}
|
|
604
|
+
*/
|
|
605
|
+
r(this, "_transitionDuration", 300);
|
|
606
|
+
/**
|
|
607
|
+
* The duration time (in milliseconds) for the transition from closed to open states.
|
|
608
|
+
*
|
|
609
|
+
* @protected
|
|
610
|
+
*
|
|
611
|
+
* @type {number}
|
|
612
|
+
*/
|
|
613
|
+
r(this, "_openDuration", -1);
|
|
614
|
+
/**
|
|
615
|
+
* The duration time (in milliseconds) for the transition from open to closed states.
|
|
616
|
+
*
|
|
617
|
+
* @protected
|
|
618
|
+
*
|
|
619
|
+
* @type {number}
|
|
620
|
+
*/
|
|
621
|
+
r(this, "_closeDuration", -1);
|
|
622
|
+
/**
|
|
623
|
+
* A flag to decide if the accordion items can be navigated by arrows.
|
|
624
|
+
*
|
|
625
|
+
* @protected
|
|
626
|
+
*
|
|
627
|
+
* @type {boolean}
|
|
628
|
+
*/
|
|
629
|
+
r(this, "_optionalKeySupport", !0);
|
|
630
|
+
/**
|
|
631
|
+
* A flag to decide if multiple accordions can be open at the same time.
|
|
632
|
+
*
|
|
633
|
+
* If set to false, only one accordion can be open at a time.
|
|
634
|
+
*
|
|
635
|
+
* @protected
|
|
636
|
+
*
|
|
637
|
+
* @type {boolean}
|
|
638
|
+
*/
|
|
639
|
+
r(this, "_allowMultipleExpand", !0);
|
|
640
|
+
/**
|
|
641
|
+
* A flag to decide if no accordions can be opened at the same time.
|
|
642
|
+
*
|
|
643
|
+
* If set to false, at least one accordion must be open at all times.
|
|
644
|
+
*
|
|
645
|
+
* @protected
|
|
646
|
+
*
|
|
647
|
+
* @type {boolean}
|
|
648
|
+
*/
|
|
649
|
+
r(this, "_allowNoExpand", !0);
|
|
650
|
+
/**
|
|
651
|
+
* The index of the current child node.
|
|
652
|
+
*
|
|
653
|
+
* @protected
|
|
654
|
+
*
|
|
655
|
+
* @type {number}
|
|
656
|
+
*/
|
|
657
|
+
r(this, "_currentChild", 0);
|
|
658
|
+
/**
|
|
659
|
+
* The prefix to use for CSS custom properties.
|
|
660
|
+
*
|
|
661
|
+
* @protected
|
|
662
|
+
*
|
|
663
|
+
* @type {string}
|
|
664
|
+
*/
|
|
665
|
+
r(this, "_prefix", "graupl-");
|
|
666
|
+
/**
|
|
667
|
+
* The key used to generate IDs throughout the accordion.
|
|
668
|
+
*
|
|
669
|
+
* @protected
|
|
670
|
+
*
|
|
671
|
+
* @type {string}
|
|
672
|
+
*/
|
|
673
|
+
r(this, "_key", "");
|
|
674
|
+
/**
|
|
675
|
+
* errors - The list of errors found during validation.
|
|
676
|
+
*
|
|
677
|
+
* @protected
|
|
678
|
+
*
|
|
679
|
+
* @type {string[]}
|
|
680
|
+
*/
|
|
681
|
+
r(this, "_errors", []);
|
|
682
|
+
this._dom.accordion = t, this._selectors.accordionItems = i, this._selectors.accordionItemToggles = o, this._selectors.accordionItemHeaders = n, this._selectors.accordionItemContents = a, this._openClass = l || "", this._closeClass = d || "", this._transitionClass = f || "", this._transitionDuration = c, this._openDuration = b, this._closeDuration = A, this._optionalKeySupport = I, this._allowMultipleExpand = k, this._allowNoExpand = D, this._prefix = x || "", this._key = $ || "", T && this.initialize();
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Initializes the accordion.
|
|
686
|
+
*/
|
|
687
|
+
initialize() {
|
|
688
|
+
try {
|
|
689
|
+
if (!this._validate())
|
|
690
|
+
throw new Error(
|
|
691
|
+
`Graupl Accordion: cannot initialize accordion. The following errors have been found:
|
|
692
|
+
- ${this.errors.join(
|
|
693
|
+
`
|
|
694
|
+
- `
|
|
695
|
+
)}`
|
|
696
|
+
);
|
|
697
|
+
this._generateKey(), this._setDOMElements(), this._setIds(), this._createChildElements(), this._handleFocus(), this._handleClick(), this._handleKeydown(), this._handleKeyup(), this._setTransitionDurations(), y.initializeStorage("accordions"), y.pushToStorage("accordions", this.dom.accordion.id, this);
|
|
698
|
+
} catch (t) {
|
|
699
|
+
console.error(t);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* The class(es) to apply when the accordion is open.
|
|
704
|
+
*
|
|
705
|
+
* @type {string|string[]}
|
|
706
|
+
*
|
|
707
|
+
* @see _openClass
|
|
708
|
+
*/
|
|
709
|
+
get openClass() {
|
|
710
|
+
return this._openClass;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* The class(es) to apply when the accordion is closed.
|
|
714
|
+
*
|
|
715
|
+
* @type {string|string[]}
|
|
716
|
+
*
|
|
717
|
+
* @see _closeClass
|
|
718
|
+
*/
|
|
719
|
+
get closeClass() {
|
|
720
|
+
return this._closeClass;
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* The class(es) to apply when the accordion is transitioning between open and closed.
|
|
724
|
+
*
|
|
725
|
+
* @type {string|string[]}
|
|
726
|
+
*
|
|
727
|
+
* @see _transitionClass
|
|
728
|
+
*/
|
|
729
|
+
get transitionClass() {
|
|
730
|
+
return this._transitionClass;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* The duration time (in milliseconds) for the transition between open and closed states.
|
|
734
|
+
*
|
|
735
|
+
* @type {number}
|
|
736
|
+
*
|
|
737
|
+
* @see _transitionDuration
|
|
738
|
+
*/
|
|
739
|
+
get transitionDuration() {
|
|
740
|
+
return this._transitionDuration;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* The duration time (in milliseconds) for the transition from closed to open states.
|
|
744
|
+
*
|
|
745
|
+
* If openDuration is set to -1, the transitionDuration will be used instead.
|
|
746
|
+
*
|
|
747
|
+
* @type {number}
|
|
748
|
+
*
|
|
749
|
+
* @see _openDuration
|
|
750
|
+
*/
|
|
751
|
+
get openDuration() {
|
|
752
|
+
return this._openDuration === -1 ? this.transitionDuration : this._openDuration;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* The duration time (in milliseconds) for the transition from open to closed states.
|
|
756
|
+
*
|
|
757
|
+
* If closeDuration is set to -1, the transitionDuration will be used instead.
|
|
758
|
+
*
|
|
759
|
+
* @type {number}
|
|
760
|
+
*
|
|
761
|
+
* @see _closeDuration
|
|
762
|
+
*/
|
|
763
|
+
get closeDuration() {
|
|
764
|
+
return this._closeDuration === -1 ? this.transitionDuration : this._closeDuration;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* The current index of the accordion item.
|
|
768
|
+
*
|
|
769
|
+
* @readonly
|
|
770
|
+
*
|
|
771
|
+
* @type {number}
|
|
772
|
+
*
|
|
773
|
+
* @see _currentChild
|
|
774
|
+
*/
|
|
775
|
+
get currentChild() {
|
|
776
|
+
return this._currentChild;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* The dom elements of the accordion.
|
|
780
|
+
*
|
|
781
|
+
* @readonly
|
|
782
|
+
*
|
|
783
|
+
* @type {object}
|
|
784
|
+
*
|
|
785
|
+
* @see _dom
|
|
786
|
+
*/
|
|
787
|
+
get dom() {
|
|
788
|
+
return this._dom;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* The elements of the accordion.
|
|
792
|
+
*
|
|
793
|
+
* @readonly
|
|
794
|
+
*
|
|
795
|
+
* @type {object}
|
|
796
|
+
*
|
|
797
|
+
* @see _elements
|
|
798
|
+
*/
|
|
799
|
+
get elements() {
|
|
800
|
+
return this._elements;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* The selectors used for the accordion and accordion items.
|
|
804
|
+
*
|
|
805
|
+
* @readonly
|
|
806
|
+
*
|
|
807
|
+
* @type {boolean}
|
|
808
|
+
*
|
|
809
|
+
* @see _selectors
|
|
810
|
+
*/
|
|
811
|
+
get selectors() {
|
|
812
|
+
return this._selectors;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* A flag to decide if the accordion items can be navigated by arrows.
|
|
816
|
+
*
|
|
817
|
+
* @readonly
|
|
818
|
+
*
|
|
819
|
+
* @type {boolean}
|
|
820
|
+
*
|
|
821
|
+
* @see _optionalKeySupport
|
|
822
|
+
*/
|
|
823
|
+
get optionalKeySupport() {
|
|
824
|
+
return this._optionalKeySupport;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* The currently selected accordion item.
|
|
828
|
+
*
|
|
829
|
+
* @readonly
|
|
830
|
+
*
|
|
831
|
+
* @type {AccordionItem}
|
|
832
|
+
*/
|
|
833
|
+
get currentAccordionItem() {
|
|
834
|
+
return this.elements.accordionItems[this.currentChild];
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* The currently open accordion items.
|
|
838
|
+
*
|
|
839
|
+
* @readonly
|
|
840
|
+
*
|
|
841
|
+
* @type {AccordionItem[]}
|
|
842
|
+
*/
|
|
843
|
+
get openAccordionItems() {
|
|
844
|
+
return this.elements.accordionItems.filter((t) => t.isOpen);
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* A flag to decide if multiple accordions can be open at the same time.
|
|
848
|
+
*
|
|
849
|
+
* @type {boolean}
|
|
850
|
+
*
|
|
851
|
+
* @see _allowMultipleExpand
|
|
852
|
+
*/
|
|
853
|
+
get allowMultipleExpand() {
|
|
854
|
+
return this._allowMultipleExpand;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* A flag to decide if no accordions can be opened at the same time.
|
|
858
|
+
*
|
|
859
|
+
* @type {boolean}
|
|
860
|
+
*
|
|
861
|
+
* @see _allowNoExpand
|
|
862
|
+
*/
|
|
863
|
+
get allowNoExpand() {
|
|
864
|
+
return this._allowNoExpand;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* The prefix to use for CSS custom properties.
|
|
868
|
+
*
|
|
869
|
+
* @type {string}
|
|
870
|
+
*
|
|
871
|
+
* @see _prefix
|
|
872
|
+
*/
|
|
873
|
+
get prefix() {
|
|
874
|
+
return this._prefix;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* The key used to generate IDs throughout the accordion.
|
|
878
|
+
*
|
|
879
|
+
* @type {string}
|
|
880
|
+
*
|
|
881
|
+
* @see _key
|
|
882
|
+
*/
|
|
883
|
+
get key() {
|
|
884
|
+
return this._key;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* An array to hold error messages.
|
|
888
|
+
*
|
|
889
|
+
* @readonly
|
|
890
|
+
*
|
|
891
|
+
* @type {string[]}
|
|
892
|
+
*
|
|
893
|
+
* @see _errors
|
|
894
|
+
*/
|
|
895
|
+
get errors() {
|
|
896
|
+
return this._errors;
|
|
897
|
+
}
|
|
898
|
+
set openClass(t) {
|
|
899
|
+
u({ openClass: t }), this._openClass !== t && (this._openClass = t);
|
|
900
|
+
}
|
|
901
|
+
set closeClass(t) {
|
|
902
|
+
u({ closeClass: t }), this._closeClass !== t && (this._closeClass = t);
|
|
903
|
+
}
|
|
904
|
+
set transitionClass(t) {
|
|
905
|
+
u({ transitionClass: t }), this._transitionClass !== t && (this._transitionClass = t);
|
|
906
|
+
}
|
|
907
|
+
set transitionDuration(t) {
|
|
908
|
+
s("number", { value: t }), this._transitionDuration !== t && (this._transitionDuration = t, this._setTransitionDurations());
|
|
909
|
+
}
|
|
910
|
+
set openDuration(t) {
|
|
911
|
+
s("number", { value: t }), this._openDuration !== t && (this._openDuration = t, this._setTransitionDurations());
|
|
912
|
+
}
|
|
913
|
+
set closeDuration(t) {
|
|
914
|
+
s("number", { value: t }), this._closeDuration !== t && (this._closeDuration = t, this._setTransitionDurations());
|
|
915
|
+
}
|
|
916
|
+
set currentChild(t) {
|
|
917
|
+
s("number", { value: t }), this._currentChild !== t && t >= 0 && t < this.elements.accordionItems.length && (this._currentChild = t);
|
|
918
|
+
}
|
|
919
|
+
set accordionItems(t) {
|
|
920
|
+
s("object", { value: t }), t != null && t.isArray() && t.every((i) => i instanceof C) && (this._accordionItems = t);
|
|
921
|
+
}
|
|
922
|
+
set allowMultipleExpand(t) {
|
|
923
|
+
s("boolean", { value: t }), this._allowMultipleExpand !== t && (this._allowMultipleExpand = t);
|
|
924
|
+
}
|
|
925
|
+
set allowNoExpand(t) {
|
|
926
|
+
s("boolean", { value: t }), this._allowNoExpand !== t && (this._allowNoExpand = t);
|
|
927
|
+
}
|
|
928
|
+
set prefix(t) {
|
|
929
|
+
s("string", { value: t }), this._prefix !== t && (this._prefix = t);
|
|
930
|
+
}
|
|
931
|
+
set key(t) {
|
|
932
|
+
s("string", { value: t }), this._key !== t && (this._key = t);
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Sets DOM elements.
|
|
936
|
+
*
|
|
937
|
+
* Elements listed in _domLock cannot be set using this method.
|
|
938
|
+
*
|
|
939
|
+
* @protected
|
|
940
|
+
*
|
|
941
|
+
* @param {string} elementType - The type of element to populate.
|
|
942
|
+
* @param {HTMLElement} [base = this.dom.accordion] - The element used as the base for the querySelect.
|
|
943
|
+
* @param {boolean} [overwrite = true] - A flag to set if the existing elements will be overwritten.
|
|
944
|
+
* @param {boolean} [strict = false] - A flag to set if the elements must be direct children of the base.
|
|
945
|
+
*/
|
|
946
|
+
_setDOMElementType(t, i = this.dom.accordion, o = !0, n = !1) {
|
|
947
|
+
if (typeof this.selectors[t] == "string") {
|
|
948
|
+
if (this._domLock.includes(t))
|
|
949
|
+
throw new Error(
|
|
950
|
+
`Graupl ${this.contructor.name}: "${t}" element cannot be set through _setDOMElementType.`
|
|
951
|
+
);
|
|
952
|
+
i !== this.dom.accordion && g(HTMLElement, { base: i });
|
|
953
|
+
const l = Array.from(
|
|
954
|
+
i.querySelectorAll(this.selectors[t])
|
|
955
|
+
).filter(
|
|
956
|
+
(d) => n ? d.parentElement === i : !0
|
|
957
|
+
);
|
|
958
|
+
o ? this._dom[t] = l : this._dom[t] = [
|
|
959
|
+
...this._dom[t],
|
|
960
|
+
...l
|
|
961
|
+
];
|
|
962
|
+
} else
|
|
963
|
+
throw new Error(
|
|
964
|
+
`Graupl ${this.contructor.name}: "${t}" is not a valid element type.`
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Resets DOM elements.
|
|
969
|
+
*
|
|
970
|
+
* Elements listed in _domLock cannot be reset using this method.
|
|
971
|
+
*
|
|
972
|
+
* @protected
|
|
973
|
+
*
|
|
974
|
+
* @param {string} elementType - The type of element to clear.
|
|
975
|
+
*/
|
|
976
|
+
_resetDOMElementType(t) {
|
|
977
|
+
if (typeof this.selectors[t] == "string") {
|
|
978
|
+
if (this._domLock.includes(t))
|
|
979
|
+
throw new Error(
|
|
980
|
+
`Graupl ${this.contructor.name}: "${t}" element cannot be reset through _resetDOMElementType.`
|
|
981
|
+
);
|
|
982
|
+
Array.isArray(this._dom[t]) ? this._dom[t] = [] : this._dom[t] = null;
|
|
983
|
+
} else
|
|
984
|
+
throw new Error(
|
|
985
|
+
`Graupl ${this.contructor.name}: "${t}" is not a valid element type.`
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Sets all DOM elements within the accordion.
|
|
990
|
+
*
|
|
991
|
+
* Utilizes _setDOMElementType and
|
|
992
|
+
* _resetDOMElementType.
|
|
993
|
+
*
|
|
994
|
+
* @protected
|
|
995
|
+
*/
|
|
996
|
+
_setDOMElements() {
|
|
997
|
+
this._setDOMElementType("accordionItems"), this._resetDOMElementType("accordionItemToggles"), this.dom.accordionItems.forEach((t) => {
|
|
998
|
+
this._setDOMElementType("accordionItemToggles", t, !1), this._setDOMElementType("accordionItemHeaders", t, !1), this._setDOMElementType("accordionItemContents", t, !1);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Generates a key for the accordion.
|
|
1003
|
+
*
|
|
1004
|
+
* @param {boolean} [regenerate = false] - A flag to determine if the key should be regenerated.
|
|
1005
|
+
*/
|
|
1006
|
+
_generateKey(t = !1) {
|
|
1007
|
+
(this.key === "" || t) && (this.key = Math.random().toString(36).replace(/[^a-z]+/g, "").substring(0, 10));
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Sets the IDs of the accordion and it's children if they do not already exist.
|
|
1011
|
+
*
|
|
1012
|
+
* The generated IDs use the key and follow the format:
|
|
1013
|
+
* - accordion: `accordion-${key}`
|
|
1014
|
+
*
|
|
1015
|
+
* @protected
|
|
1016
|
+
*/
|
|
1017
|
+
_setIds() {
|
|
1018
|
+
this.dom.accordion.id = this.dom.accordion.id || `accordion-${this.key}`;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Creates and initializes all accordion items.
|
|
1022
|
+
*
|
|
1023
|
+
* @protected
|
|
1024
|
+
*/
|
|
1025
|
+
_createChildElements() {
|
|
1026
|
+
this.dom.accordionItems.forEach((t, i) => {
|
|
1027
|
+
const o = new C({
|
|
1028
|
+
accordionItemElement: t,
|
|
1029
|
+
accordionItemToggleElement: this.dom.accordionItemToggles[i],
|
|
1030
|
+
accordionItemHeaderElement: this.dom.accordionItemHeaders[i],
|
|
1031
|
+
accordionItemContentElement: this.dom.accordionItemContents[i],
|
|
1032
|
+
parentAccordion: this
|
|
1033
|
+
});
|
|
1034
|
+
o.initialize(), this.elements.accordionItems.push(o);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Validates all aspects of the accordion item to ensure proper functionality.
|
|
1039
|
+
*
|
|
1040
|
+
* @protected
|
|
1041
|
+
*
|
|
1042
|
+
* @return {boolean} - The result of the validation.
|
|
1043
|
+
*/
|
|
1044
|
+
_validate() {
|
|
1045
|
+
let t = !0;
|
|
1046
|
+
const i = g(HTMLElement, {
|
|
1047
|
+
accordionElement: this.dom.accordion
|
|
1048
|
+
});
|
|
1049
|
+
i || (this._errors.push(i.message), t = !1);
|
|
1050
|
+
const o = E({
|
|
1051
|
+
accordionItemSelector: this._selectors.accordionItems,
|
|
1052
|
+
accordionItemToggleSelector: this._selectors.accordionItemToggles,
|
|
1053
|
+
accordionItemHeaderSelector: this._selectors.accordionItemHeaders,
|
|
1054
|
+
accordionItemContentSelector: this._selectors.accordionItemContents
|
|
1055
|
+
});
|
|
1056
|
+
if (o || (this._errors.push(o.message), t = !1), this._openClass !== "") {
|
|
1057
|
+
const c = u({ openClass: this._openClass });
|
|
1058
|
+
c.status || (this._errors.push(c.error.message), t = !1);
|
|
1059
|
+
}
|
|
1060
|
+
if (this._closeClass !== "") {
|
|
1061
|
+
const c = u({
|
|
1062
|
+
closeClass: this._closeClass
|
|
1063
|
+
});
|
|
1064
|
+
c.status || (this._errors.push(c.error.message), t = !1);
|
|
1065
|
+
}
|
|
1066
|
+
if (this._transitionClass !== "") {
|
|
1067
|
+
const c = u({
|
|
1068
|
+
transitionClass: this._transitionClass
|
|
1069
|
+
});
|
|
1070
|
+
c.status || (this._errors.push(c.error.message), t = !1);
|
|
1071
|
+
}
|
|
1072
|
+
const n = s("number", {
|
|
1073
|
+
transitionDuration: this._transitionDuration
|
|
1074
|
+
});
|
|
1075
|
+
n.status || (this._errors.push(n.error.message), t = !1);
|
|
1076
|
+
const a = s("number", {
|
|
1077
|
+
openDuration: this._openDuration
|
|
1078
|
+
});
|
|
1079
|
+
a.status || (this._errors.push(a.error.message), t = !1);
|
|
1080
|
+
const l = s("number", {
|
|
1081
|
+
closeDuration: this._closeDuration
|
|
1082
|
+
});
|
|
1083
|
+
l.status || (this._errors.push(l.error.message), t = !1);
|
|
1084
|
+
const d = s("boolean", {
|
|
1085
|
+
optionalKeySupport: this._optionalKeySupport,
|
|
1086
|
+
allowMultipleExpand: this._allowMultipleExpand,
|
|
1087
|
+
allowNoExpand: this._allowNoExpand
|
|
1088
|
+
});
|
|
1089
|
+
if (d.status || (this._errors.push(d.error.message), t = !1), this._key !== "") {
|
|
1090
|
+
const c = s("string", { key: this._key });
|
|
1091
|
+
c.status || (this._errors.push(c.error.message), t = !1);
|
|
1092
|
+
}
|
|
1093
|
+
const f = s("string", { prefix: this._prefix });
|
|
1094
|
+
return f.status || (this._errors.push(f.error.message), t = !1), t;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Handles focus events throughout the accordion for proper use.
|
|
1098
|
+
*
|
|
1099
|
+
* - Adds a `focus` listener to every accordion item so when it gains focus,
|
|
1100
|
+
* it will set the accordion's current child to the index of the item.
|
|
1101
|
+
*
|
|
1102
|
+
* @protected
|
|
1103
|
+
*/
|
|
1104
|
+
_handleFocus() {
|
|
1105
|
+
this.elements.accordionItems.forEach((t, i) => {
|
|
1106
|
+
t.dom.toggle.addEventListener("focus", () => {
|
|
1107
|
+
this.currentChild = i;
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Handles click events throughout the accordion item for proper use.
|
|
1113
|
+
*
|
|
1114
|
+
* - Adds a `pointerup` listener to the accordion item toggles that will toggle each accordion item.
|
|
1115
|
+
*
|
|
1116
|
+
* @protected
|
|
1117
|
+
*/
|
|
1118
|
+
_handleClick() {
|
|
1119
|
+
this.elements.accordionItems.forEach((t, i) => {
|
|
1120
|
+
t.dom.toggle.addEventListener("pointerup", () => {
|
|
1121
|
+
this.currentChild = i, t.toggle();
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Handles keydown events throughout the accordion item for proper use.
|
|
1127
|
+
*
|
|
1128
|
+
* This method exists to assist the _handleKeyup method.
|
|
1129
|
+
*
|
|
1130
|
+
* - Adds a `keydown` listener to all accordion item toggles.
|
|
1131
|
+
* - Blocks propagation on "Space" and "Enter" keys.
|
|
1132
|
+
* - _If_ optionalKeySupport is enabled, blocks propagation on the following keys:
|
|
1133
|
+
* - "ArrowDown", "ArrowUp", "Home", and "End".
|
|
1134
|
+
*/
|
|
1135
|
+
_handleKeydown() {
|
|
1136
|
+
this.dom.accordionItemToggles.forEach((t) => {
|
|
1137
|
+
t.addEventListener("keydown", (i) => {
|
|
1138
|
+
const o = w(i);
|
|
1139
|
+
(["Space", "Enter"].includes(o) || this.optionalKeySupport && ["ArrowDown", "ArrowUp", "Home", "End"].includes(o)) && h(i);
|
|
1140
|
+
});
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Handles keyup events throughout the accordion item for proper use.
|
|
1145
|
+
*
|
|
1146
|
+
* Adds the follow keybindings (explanations are taken from the WAI ARIA Practices Guide Accordion Pattern):
|
|
1147
|
+
*
|
|
1148
|
+
* - `Enter` or `Space`:
|
|
1149
|
+
* - When focus is on the accordion header for a collapsed panel, expands the associated panel. If the implementation allows only one panel to be expanded, and if another panel is expanded, collapses that panel.
|
|
1150
|
+
* - When focus is on the accordion header for an expanded panel, collapses the panel if the implementation supports collapsing. Some implementations require one panel to be expanded at all times and allow only one panel to be expanded; so, they do not support a collapse function.
|
|
1151
|
+
* - `Tab`: Moves focus to the next focusable element; all focusable elements in the accordion are included in the page `Tab` sequence.
|
|
1152
|
+
* - `Shift + Tab`: Moves focus to the previous focusable element; all focusable elements in the accordion are included in the page `Tab` sequence.
|
|
1153
|
+
* - `Down Arrow` (Optional): If focus is on an accordion header, moves focus to the next accordion header. If focus is on the last accordion header, either does nothing or moves focus to the first accordion header.
|
|
1154
|
+
* - `Up Arrow` (Optional): If focus is on an accordion header, moves focus to the previous accordion header. If focus is on the first accordion header, either does nothing or moves focus to the last accordion header.
|
|
1155
|
+
* - `Home` (Optional): When focus is on an accordion header, moves focus to the first accordion header.
|
|
1156
|
+
* - `End` (Optional): When focus is on an accordion header, moves focus to the last accordion header.
|
|
1157
|
+
*
|
|
1158
|
+
* Note: When the above explanations mention "accordion header", they are referring to the accordion item toggle.
|
|
1159
|
+
*/
|
|
1160
|
+
_handleKeyup() {
|
|
1161
|
+
this.dom.accordionItemToggles.forEach((t) => {
|
|
1162
|
+
t.addEventListener("keyup", (i) => {
|
|
1163
|
+
const o = w(i);
|
|
1164
|
+
switch (o) {
|
|
1165
|
+
case "Space":
|
|
1166
|
+
case "Enter":
|
|
1167
|
+
h(i), this.currentAccordionItem.toggle();
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
if (this.optionalKeySupport)
|
|
1171
|
+
switch (o) {
|
|
1172
|
+
case "Home":
|
|
1173
|
+
h(i), this.focusFirstChild();
|
|
1174
|
+
break;
|
|
1175
|
+
case "End":
|
|
1176
|
+
h(i), this.focusLastChild();
|
|
1177
|
+
break;
|
|
1178
|
+
case "ArrowDown":
|
|
1179
|
+
h(i), this.focusNextChild();
|
|
1180
|
+
break;
|
|
1181
|
+
case "ArrowUp":
|
|
1182
|
+
h(i), this.focusPreviousChild();
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Sets the transition durations of the accordion as a CSS custom properties.
|
|
1190
|
+
*
|
|
1191
|
+
* The custom properties are:
|
|
1192
|
+
* - `--graupl-accordion-transition-duration`,
|
|
1193
|
+
* - `--graupl-accordion-open-transition-duration`, and
|
|
1194
|
+
* - `--graupl-accordion-close-transition-duration`.
|
|
1195
|
+
*
|
|
1196
|
+
* The prefix of `graupl-` can be changed by setting the accordion's prefix value.
|
|
1197
|
+
*
|
|
1198
|
+
* @protected
|
|
1199
|
+
*/
|
|
1200
|
+
_setTransitionDurations() {
|
|
1201
|
+
this.dom.accordion.style.setProperty(
|
|
1202
|
+
`--${this.prefix}accordion-transition-duration`,
|
|
1203
|
+
`${this.transitionDuration}ms`
|
|
1204
|
+
), this.dom.accordion.style.setProperty(
|
|
1205
|
+
`--${this.prefix}accordion-open-transition-duration`,
|
|
1206
|
+
`${this.openDuration}ms`
|
|
1207
|
+
), this.dom.accordion.style.setProperty(
|
|
1208
|
+
`--${this.prefix}accordion-close-transition-duration`,
|
|
1209
|
+
`${this.closeDuration}ms`
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Focus the accordion's current child.
|
|
1214
|
+
*
|
|
1215
|
+
* @public
|
|
1216
|
+
*/
|
|
1217
|
+
focusCurrentChild() {
|
|
1218
|
+
this.currentChild !== -1 && this.currentAccordionItem.focus();
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Focuses the accordion's child at a given index.
|
|
1222
|
+
*
|
|
1223
|
+
* @public
|
|
1224
|
+
*
|
|
1225
|
+
* @param {number} index - The index of the child to focus.
|
|
1226
|
+
*/
|
|
1227
|
+
focusChild(t) {
|
|
1228
|
+
this.blurCurrentChild(), this.currentChild = t, this.focusCurrentChild();
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Focuses the accordion's first child.
|
|
1232
|
+
*
|
|
1233
|
+
* @public
|
|
1234
|
+
*/
|
|
1235
|
+
focusFirstChild() {
|
|
1236
|
+
this.focusChild(0);
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Focus the accordion's last child.
|
|
1240
|
+
*
|
|
1241
|
+
* @public
|
|
1242
|
+
*/
|
|
1243
|
+
focusLastChild() {
|
|
1244
|
+
this.focusChild(this.elements.accordionItems.length - 1);
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Focus the accordion's next child.
|
|
1248
|
+
*
|
|
1249
|
+
* @public
|
|
1250
|
+
*/
|
|
1251
|
+
focusNextChild() {
|
|
1252
|
+
this.currentChild < this.elements.accordionItems.length - 1 ? this.focusChild(this.currentChild + 1) : this.focusCurrentChild();
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Focus the accordion's previous child.
|
|
1256
|
+
*
|
|
1257
|
+
* @public
|
|
1258
|
+
*/
|
|
1259
|
+
focusPreviousChild() {
|
|
1260
|
+
this.currentChild > 0 ? this.focusChild(this.currentChild - 1) : this.focusCurrentChild();
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Blurs the accordion's current child.
|
|
1264
|
+
*
|
|
1265
|
+
* @public
|
|
1266
|
+
*/
|
|
1267
|
+
blurCurrentChild() {
|
|
1268
|
+
this.currentChild !== -1 && this.currentAccordionItem.blur();
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Open all accordion items.
|
|
1272
|
+
*
|
|
1273
|
+
* @public
|
|
1274
|
+
*/
|
|
1275
|
+
openChildren() {
|
|
1276
|
+
this.elements.accordionItems.forEach((t) => t.show());
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Close all accordion items.
|
|
1280
|
+
*
|
|
1281
|
+
* @public
|
|
1282
|
+
*/
|
|
1283
|
+
closeChildren() {
|
|
1284
|
+
this.elements.accordionItems.forEach((t) => t.hide());
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
export {
|
|
1288
|
+
V as default
|
|
1289
|
+
};
|