@y14e/tabs 1.3.10 → 1.3.12
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/dist/index.cjs +17 -40
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -101,12 +101,10 @@ var Tabs = class _Tabs {
|
|
|
101
101
|
this.#rootElement = root;
|
|
102
102
|
this.#defaults = this.#mergeOptions(this.#defaults, _Tabs.defaults);
|
|
103
103
|
this.#settings = this.#mergeOptions(this.#defaults, options);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
}
|
|
104
|
+
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, {
|
|
105
|
+
content: { duration: 0 },
|
|
106
|
+
indicator: { duration: 0 }
|
|
107
|
+
});
|
|
110
108
|
const NOT_NESTED = `:not(:scope ${this.#settings.selector.panel} *)`;
|
|
111
109
|
this.#listElements = [
|
|
112
110
|
...this.#rootElement.querySelectorAll(
|
|
@@ -160,9 +158,7 @@ var Tabs = class _Tabs {
|
|
|
160
158
|
}
|
|
161
159
|
const binding = createBinding(tabsByIndex, panel);
|
|
162
160
|
this.#bindings.set(tab, binding);
|
|
163
|
-
|
|
164
|
-
this.#bindings.set(panel, binding);
|
|
165
|
-
}
|
|
161
|
+
i < length && this.#bindings.set(panel, binding);
|
|
166
162
|
});
|
|
167
163
|
this.#initialize();
|
|
168
164
|
}
|
|
@@ -207,11 +203,7 @@ var Tabs = class _Tabs {
|
|
|
207
203
|
}
|
|
208
204
|
style2.setProperty("inline-size", "100%");
|
|
209
205
|
style2.setProperty("position", "absolute");
|
|
210
|
-
|
|
211
|
-
p.setAttribute("tabindex", "0");
|
|
212
|
-
} else {
|
|
213
|
-
p.removeAttribute("tabindex");
|
|
214
|
-
}
|
|
206
|
+
p === panel && !hasFocusable(p) ? p.setAttribute("tabindex", "0") : p.removeAttribute("tabindex");
|
|
215
207
|
});
|
|
216
208
|
this.#panelElements.forEach((p, i) => {
|
|
217
209
|
if (p === panel) {
|
|
@@ -346,17 +338,12 @@ var Tabs = class _Tabs {
|
|
|
346
338
|
"style"
|
|
347
339
|
]);
|
|
348
340
|
this.#listElements.forEach((list, i) => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
if (this.#settings.vertical) {
|
|
353
|
-
list.setAttribute("aria-orientation", "vertical");
|
|
354
|
-
}
|
|
341
|
+
this.#settings.avoidDuplicates && i && list.setAttribute("aria-hidden", "true");
|
|
342
|
+
this.#settings.vertical && list.setAttribute("aria-orientation", "vertical");
|
|
355
343
|
list.setAttribute("role", "tablist");
|
|
356
344
|
});
|
|
357
345
|
saveAttributes(this.#tabElements, [
|
|
358
346
|
"aria-controls",
|
|
359
|
-
"aria-selected",
|
|
360
347
|
"id",
|
|
361
348
|
"role",
|
|
362
349
|
"style",
|
|
@@ -368,17 +355,13 @@ var Tabs = class _Tabs {
|
|
|
368
355
|
if (!panel) {
|
|
369
356
|
return;
|
|
370
357
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
);
|
|
376
|
-
}
|
|
358
|
+
i < this.#panelElements.length && saveAttributes(
|
|
359
|
+
[panel],
|
|
360
|
+
["aria-controls", "aria-labelledby", "id", "role", "tabindex"]
|
|
361
|
+
);
|
|
377
362
|
panel.id ||= `tabs-panel-${id}`;
|
|
378
363
|
addTokenToAttribute(tab, "aria-controls", panel.id);
|
|
379
|
-
|
|
380
|
-
tab.setAttribute("aria-selected", "false");
|
|
381
|
-
}
|
|
364
|
+
!tab.hasAttribute("aria-selected") && tab.setAttribute("aria-selected", "false");
|
|
382
365
|
const isAvoided = this.#isAvoidedTab(tab);
|
|
383
366
|
if (!isAvoided) {
|
|
384
367
|
tab.id ||= `tabs-tab-${id}`;
|
|
@@ -388,9 +371,7 @@ var Tabs = class _Tabs {
|
|
|
388
371
|
"tabindex",
|
|
389
372
|
tab.ariaSelected === "true" && !isAvoided ? "0" : "-1"
|
|
390
373
|
);
|
|
391
|
-
|
|
392
|
-
tab.style.setProperty("pointer-events", "none");
|
|
393
|
-
}
|
|
374
|
+
!isFocusable(tab) && tab.style.setProperty("pointer-events", "none");
|
|
394
375
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
395
376
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
396
377
|
tab.addEventListener("focus", this.#onTabFocus, { signal });
|
|
@@ -406,9 +387,7 @@ var Tabs = class _Tabs {
|
|
|
406
387
|
});
|
|
407
388
|
this.#panelElements.forEach((panel) => {
|
|
408
389
|
panel.setAttribute("role", "tabpanel");
|
|
409
|
-
|
|
410
|
-
panel.setAttribute("tabindex", "0");
|
|
411
|
-
}
|
|
390
|
+
!panel.hasAttribute("hidden") && !hasFocusable(panel) && panel.setAttribute("tabindex", "0");
|
|
412
391
|
panel.addEventListener("beforematch", this.#onPanelBeforeMatch, {
|
|
413
392
|
signal
|
|
414
393
|
});
|
|
@@ -490,9 +469,7 @@ var Tabs = class _Tabs {
|
|
|
490
469
|
return;
|
|
491
470
|
}
|
|
492
471
|
newTab.focus();
|
|
493
|
-
|
|
494
|
-
newTab.click();
|
|
495
|
-
}
|
|
472
|
+
!this.#settings.manual && newTab.click();
|
|
496
473
|
};
|
|
497
474
|
#onPanelBeforeMatch = (event) => {
|
|
498
475
|
const panel = event.currentTarget;
|
|
@@ -643,7 +620,7 @@ function isFocusable(element) {
|
|
|
643
620
|
* Tabs
|
|
644
621
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
645
622
|
*
|
|
646
|
-
* @version 1.3.
|
|
623
|
+
* @version 1.3.12
|
|
647
624
|
* @author Yusuke Kamiyamane
|
|
648
625
|
* @license MIT
|
|
649
626
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -99,12 +99,10 @@ var Tabs = class _Tabs {
|
|
|
99
99
|
this.#rootElement = root;
|
|
100
100
|
this.#defaults = this.#mergeOptions(this.#defaults, _Tabs.defaults);
|
|
101
101
|
this.#settings = this.#mergeOptions(this.#defaults, options);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
}
|
|
102
|
+
matchMedia("(prefers-reduced-motion: reduce)").matches && Object.assign(this.#settings.animation, {
|
|
103
|
+
content: { duration: 0 },
|
|
104
|
+
indicator: { duration: 0 }
|
|
105
|
+
});
|
|
108
106
|
const NOT_NESTED = `:not(:scope ${this.#settings.selector.panel} *)`;
|
|
109
107
|
this.#listElements = [
|
|
110
108
|
...this.#rootElement.querySelectorAll(
|
|
@@ -158,9 +156,7 @@ var Tabs = class _Tabs {
|
|
|
158
156
|
}
|
|
159
157
|
const binding = createBinding(tabsByIndex, panel);
|
|
160
158
|
this.#bindings.set(tab, binding);
|
|
161
|
-
|
|
162
|
-
this.#bindings.set(panel, binding);
|
|
163
|
-
}
|
|
159
|
+
i < length && this.#bindings.set(panel, binding);
|
|
164
160
|
});
|
|
165
161
|
this.#initialize();
|
|
166
162
|
}
|
|
@@ -205,11 +201,7 @@ var Tabs = class _Tabs {
|
|
|
205
201
|
}
|
|
206
202
|
style2.setProperty("inline-size", "100%");
|
|
207
203
|
style2.setProperty("position", "absolute");
|
|
208
|
-
|
|
209
|
-
p.setAttribute("tabindex", "0");
|
|
210
|
-
} else {
|
|
211
|
-
p.removeAttribute("tabindex");
|
|
212
|
-
}
|
|
204
|
+
p === panel && !hasFocusable(p) ? p.setAttribute("tabindex", "0") : p.removeAttribute("tabindex");
|
|
213
205
|
});
|
|
214
206
|
this.#panelElements.forEach((p, i) => {
|
|
215
207
|
if (p === panel) {
|
|
@@ -344,17 +336,12 @@ var Tabs = class _Tabs {
|
|
|
344
336
|
"style"
|
|
345
337
|
]);
|
|
346
338
|
this.#listElements.forEach((list, i) => {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
if (this.#settings.vertical) {
|
|
351
|
-
list.setAttribute("aria-orientation", "vertical");
|
|
352
|
-
}
|
|
339
|
+
this.#settings.avoidDuplicates && i && list.setAttribute("aria-hidden", "true");
|
|
340
|
+
this.#settings.vertical && list.setAttribute("aria-orientation", "vertical");
|
|
353
341
|
list.setAttribute("role", "tablist");
|
|
354
342
|
});
|
|
355
343
|
saveAttributes(this.#tabElements, [
|
|
356
344
|
"aria-controls",
|
|
357
|
-
"aria-selected",
|
|
358
345
|
"id",
|
|
359
346
|
"role",
|
|
360
347
|
"style",
|
|
@@ -366,17 +353,13 @@ var Tabs = class _Tabs {
|
|
|
366
353
|
if (!panel) {
|
|
367
354
|
return;
|
|
368
355
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
);
|
|
374
|
-
}
|
|
356
|
+
i < this.#panelElements.length && saveAttributes(
|
|
357
|
+
[panel],
|
|
358
|
+
["aria-controls", "aria-labelledby", "id", "role", "tabindex"]
|
|
359
|
+
);
|
|
375
360
|
panel.id ||= `tabs-panel-${id}`;
|
|
376
361
|
addTokenToAttribute(tab, "aria-controls", panel.id);
|
|
377
|
-
|
|
378
|
-
tab.setAttribute("aria-selected", "false");
|
|
379
|
-
}
|
|
362
|
+
!tab.hasAttribute("aria-selected") && tab.setAttribute("aria-selected", "false");
|
|
380
363
|
const isAvoided = this.#isAvoidedTab(tab);
|
|
381
364
|
if (!isAvoided) {
|
|
382
365
|
tab.id ||= `tabs-tab-${id}`;
|
|
@@ -386,9 +369,7 @@ var Tabs = class _Tabs {
|
|
|
386
369
|
"tabindex",
|
|
387
370
|
tab.ariaSelected === "true" && !isAvoided ? "0" : "-1"
|
|
388
371
|
);
|
|
389
|
-
|
|
390
|
-
tab.style.setProperty("pointer-events", "none");
|
|
391
|
-
}
|
|
372
|
+
!isFocusable(tab) && tab.style.setProperty("pointer-events", "none");
|
|
392
373
|
addTokenToAttribute(panel, "aria-labelledby", tab.id);
|
|
393
374
|
tab.addEventListener("click", this.#onTabClick, { signal });
|
|
394
375
|
tab.addEventListener("focus", this.#onTabFocus, { signal });
|
|
@@ -404,9 +385,7 @@ var Tabs = class _Tabs {
|
|
|
404
385
|
});
|
|
405
386
|
this.#panelElements.forEach((panel) => {
|
|
406
387
|
panel.setAttribute("role", "tabpanel");
|
|
407
|
-
|
|
408
|
-
panel.setAttribute("tabindex", "0");
|
|
409
|
-
}
|
|
388
|
+
!panel.hasAttribute("hidden") && !hasFocusable(panel) && panel.setAttribute("tabindex", "0");
|
|
410
389
|
panel.addEventListener("beforematch", this.#onPanelBeforeMatch, {
|
|
411
390
|
signal
|
|
412
391
|
});
|
|
@@ -488,9 +467,7 @@ var Tabs = class _Tabs {
|
|
|
488
467
|
return;
|
|
489
468
|
}
|
|
490
469
|
newTab.focus();
|
|
491
|
-
|
|
492
|
-
newTab.click();
|
|
493
|
-
}
|
|
470
|
+
!this.#settings.manual && newTab.click();
|
|
494
471
|
};
|
|
495
472
|
#onPanelBeforeMatch = (event) => {
|
|
496
473
|
const panel = event.currentTarget;
|
|
@@ -641,7 +618,7 @@ function isFocusable(element) {
|
|
|
641
618
|
* Tabs
|
|
642
619
|
* WAI-ARIA compliant tabs pattern implementation in TypeScript.
|
|
643
620
|
*
|
|
644
|
-
* @version 1.3.
|
|
621
|
+
* @version 1.3.12
|
|
645
622
|
* @author Yusuke Kamiyamane
|
|
646
623
|
* @license MIT
|
|
647
624
|
* @copyright Copyright (c) Yusuke Kamiyamane
|