inclusive-elements 0.3.4 → 0.4.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 CHANGED
@@ -29,6 +29,7 @@ Detailed descriptions and usage instructions are contained within each element:
29
29
  - [Menu](src/menu)
30
30
  - [Modal](src/modal)
31
31
  - [Popup](src/popup)
32
+ - [Tabs](src/tabs)
32
33
  - [Toolbar](src/toolbar)
33
34
  - [Tooltip](src/tooltip)
34
35
 
@@ -1,26 +1,27 @@
1
1
  var T = Object.defineProperty;
2
- var D = (o, r, t) => r in o ? T(o, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[r] = t;
3
- var s = (o, r, t) => (D(o, typeof r != "symbol" ? r + "" : r, t), t);
4
- import { move as k, hello as h, goodbye as d, cancel as v } from "hello-goodbye";
5
- import { isFocusable as H, focusable as A } from "tabbable";
6
- import { createFocusTrap as O } from "focus-trap";
7
- import { autoUpdate as M, computePosition as g, shift as L, flip as x, size as K } from "@floating-ui/dom";
8
- class I extends HTMLElement {
2
+ var D = (r, a, t) => a in r ? T(r, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[a] = t;
3
+ var s = (r, a, t) => (D(r, typeof a != "symbol" ? a + "" : a, t), t);
4
+ import { move as A, hello as h, goodbye as c, cancel as v } from "hello-goodbye";
5
+ import { isFocusable as H, focusable as k } from "tabbable";
6
+ import { createFocusTrap as K } from "focus-trap";
7
+ import { autoUpdate as M, computePosition as E, shift as L, flip as x, size as O } from "@floating-ui/dom";
8
+ class F extends HTMLElement {
9
9
  constructor() {
10
10
  super(...arguments);
11
- s(this, "onOpen", (t) => {
12
- this.querySelectorAll(
13
- ":scope > ui-disclosure"
14
- ).forEach((e) => {
15
- e.open = e === t.target, this.required && e.toggleAttribute("disabled", e === t.target);
11
+ s(this, "onToggle", (t) => {
12
+ const e = t.target;
13
+ e.open && this.querySelectorAll(
14
+ ":scope > :is(ui-disclosure, details)"
15
+ ).forEach((i) => {
16
+ i.toggleAttribute("open", i === e), this.required && i.toggleAttribute("disabled", i === e);
16
17
  });
17
18
  });
18
19
  }
19
20
  connectedCallback() {
20
- this.addEventListener("open", this.onOpen, { capture: !0 });
21
+ this.addEventListener("toggle", this.onToggle, { capture: !0 });
21
22
  }
22
23
  disconnectedCallback() {
23
- this.removeEventListener("open", this.onOpen, { capture: !0 });
24
+ this.removeEventListener("toggle", this.onToggle, { capture: !0 });
24
25
  }
25
26
  get required() {
26
27
  return this.hasAttribute("required");
@@ -46,7 +47,7 @@ const w = class extends HTMLElement {
46
47
  }
47
48
  show(t, e = {}) {
48
49
  const i = e.key || t.dataset.key || String(this.index++);
49
- t.dataset.key = i, this.contains(t) ? h(t) : e.animate === !1 ? this.append(t) : k(this.children, () => {
50
+ t.dataset.key = i, this.contains(t) ? h(t) : e.animate === !1 ? this.append(t) : A(this.children, () => {
50
51
  this.append(t), h(t);
51
52
  });
52
53
  const n = Number(
@@ -69,8 +70,8 @@ const w = class extends HTMLElement {
69
70
  });
70
71
  return;
71
72
  }
72
- k(this.children, () => {
73
- d(t).then(() => this.removeChild(t));
73
+ A(this.children, () => {
74
+ c(t).then(() => this.removeChild(t));
74
75
  }), this.clearTimeout(t);
75
76
  }
76
77
  clear() {
@@ -102,12 +103,12 @@ const w = class extends HTMLElement {
102
103
  this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
103
104
  }
104
105
  };
105
- let b = w;
106
- s(b, "duration", 1e4);
107
- function C(o) {
108
- return o.altKey || o.ctrlKey || o.metaKey || o.shiftKey || o.button !== void 0 && o.button !== 0;
106
+ let p = w;
107
+ s(p, "duration", 1e4);
108
+ function C(r) {
109
+ return r.altKey || r.ctrlKey || r.metaKey || r.shiftKey || r.button !== void 0 && r.button !== 0;
109
110
  }
110
- class P extends HTMLElement {
111
+ class $ extends HTMLElement {
111
112
  constructor() {
112
113
  super(...arguments);
113
114
  s(this, "onButtonClick", (t) => {
@@ -136,10 +137,10 @@ class P extends HTMLElement {
136
137
  t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
137
138
  }
138
139
  wasOpened() {
139
- this.content.hidden && (this.content.hidden = !1, h(this.content), this.button.setAttribute("aria-expanded", "true"), this.dispatchEvent(new Event("open")));
140
+ this.content.hidden && (this.content.hidden = !1, h(this.content)), this.button.setAttribute("aria-expanded", "true"), this.dispatchEvent(new Event("toggle"));
140
141
  }
141
142
  wasClosed() {
142
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), d(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
143
+ this.content.hidden || c(this.content).then(() => this.content.hidden = !0), this.button.setAttribute("aria-expanded", "false"), this.dispatchEvent(new Event("toggle"));
143
144
  }
144
145
  get button() {
145
146
  return this.querySelector("button, [role=button]");
@@ -148,7 +149,7 @@ class P extends HTMLElement {
148
149
  return this.children[1];
149
150
  }
150
151
  }
151
- const y = class extends HTMLElement {
152
+ const g = class extends HTMLElement {
152
153
  constructor() {
153
154
  super(...arguments);
154
155
  s(this, "search", "");
@@ -165,7 +166,7 @@ const y = class extends HTMLElement {
165
166
  }
166
167
  t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
167
168
  this.search = "";
168
- }, y.searchDelay), this.items.some((e) => {
169
+ }, g.searchDelay), this.items.some((e) => {
169
170
  var i;
170
171
  return ((i = e.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
171
172
  }));
@@ -192,9 +193,9 @@ const y = class extends HTMLElement {
192
193
  i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
193
194
  }
194
195
  };
195
- let f = y;
196
+ let f = g;
196
197
  s(f, "searchDelay", 800);
197
- const u = class extends HTMLElement {
198
+ const l = class extends HTMLElement {
198
199
  constructor() {
199
200
  super();
200
201
  s(this, "focusTrap");
@@ -207,8 +208,8 @@ const u = class extends HTMLElement {
207
208
  const e = this.attachShadow({ mode: "open" });
208
209
  e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
209
210
  var i;
210
- this.hasAttribute("static") ? (i = u.attention) == null || i.call(u, e.children[1]) : this.close();
211
- }), this.focusTrap = O(this, {
211
+ this.hasAttribute("static") ? (i = l.attention) == null || i.call(l, e.children[1]) : this.close();
212
+ }), this.focusTrap = K(this, {
212
213
  escapeDeactivates: !1,
213
214
  allowOutsideClick: !0,
214
215
  preventScroll: !0
@@ -218,9 +219,9 @@ const u = class extends HTMLElement {
218
219
  return ["open"];
219
220
  }
220
221
  connectedCallback() {
221
- var t, e, i, n, a, E;
222
- this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (a = this.content) != null && a.hasAttribute("tabindex") || (E = this.content) == null || E.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (p) => {
223
- p.key === "Escape" && this.open && (p.preventDefault(), p.stopPropagation(), this.close());
222
+ var t, e, i, n, o, y;
223
+ this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (o = this.content) != null && o.hasAttribute("tabindex") || (y = this.content) == null || y.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (b) => {
224
+ b.key === "Escape" && this.open && (b.preventDefault(), b.stopPropagation(), this.close());
224
225
  }), this.open && this.wasOpened();
225
226
  }
226
227
  disconnectedCallback() {
@@ -247,7 +248,7 @@ const u = class extends HTMLElement {
247
248
  }
248
249
  wasClosed() {
249
250
  var t;
250
- (t = this.focusTrap) == null || t.deactivate(), d(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
251
+ (t = this.focusTrap) == null || t.deactivate(), c(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
251
252
  }
252
253
  get backdrop() {
253
254
  var t;
@@ -257,7 +258,7 @@ const u = class extends HTMLElement {
257
258
  return this.firstElementChild;
258
259
  }
259
260
  };
260
- let m = u;
261
+ let m = l;
261
262
  s(m, "attention", (t) => t.animate(
262
263
  [
263
264
  { transform: "scale(1)" },
@@ -266,7 +267,7 @@ s(m, "attention", (t) => t.animate(
266
267
  ],
267
268
  300
268
269
  ));
269
- class $ extends HTMLElement {
270
+ class U extends HTMLElement {
270
271
  constructor() {
271
272
  super();
272
273
  s(this, "cleanup");
@@ -275,7 +276,7 @@ class $ extends HTMLElement {
275
276
  });
276
277
  s(this, "onButtonKeyDown", (t) => {
277
278
  var e;
278
- t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = A(this.content)[0]) == null || e.focus());
279
+ t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = k(this.content)[0]) == null || e.focus());
279
280
  });
280
281
  s(this, "onKeyDown", (t) => {
281
282
  t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
@@ -322,12 +323,12 @@ class $ extends HTMLElement {
322
323
  this.button,
323
324
  this.content,
324
325
  () => {
325
- g(this.button, this.content, {
326
+ E(this.button, this.content, {
326
327
  placement: this.getAttribute("placement") || "bottom",
327
328
  middleware: [
328
329
  L(),
329
330
  x(),
330
- K({
331
+ O({
331
332
  apply: ({ availableWidth: e, availableHeight: i }) => {
332
333
  Object.assign(this.content.style, {
333
334
  maxWidth: "",
@@ -352,7 +353,7 @@ class $ extends HTMLElement {
352
353
  }
353
354
  wasClosed() {
354
355
  var t;
355
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), d(this.backdrop).then(() => this.backdrop.hidden = !0), d(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
356
+ this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), c(this.backdrop).then(() => this.backdrop.hidden = !0), c(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
356
357
  }
357
358
  get backdrop() {
358
359
  var t;
@@ -365,7 +366,59 @@ class $ extends HTMLElement {
365
366
  return this.children[1];
366
367
  }
367
368
  }
368
- class U extends HTMLElement {
369
+ let S = 0;
370
+ class R extends HTMLElement {
371
+ constructor() {
372
+ super(...arguments);
373
+ s(this, "idPrefix", "tabs" + ++S);
374
+ s(this, "onKeyDown", (t) => {
375
+ const e = t.target, i = this.tabs.indexOf(e), n = this.tablist.getAttribute("aria-orientation") === "vertical";
376
+ let o = !1;
377
+ switch (t.key) {
378
+ case (n ? "ArrowUp" : "ArrowLeft"):
379
+ this.selectTab(i - 1), o = !0;
380
+ break;
381
+ case (n ? "ArrowDown" : "ArrowRight"):
382
+ this.selectTab(i + 1), o = !0;
383
+ break;
384
+ case "Home":
385
+ this.selectTab(0), o = !0;
386
+ break;
387
+ case "End":
388
+ this.selectTab(this.tabs.length - 1), o = !0;
389
+ }
390
+ o && (t.stopPropagation(), t.preventDefault());
391
+ });
392
+ s(this, "onClick", (t) => {
393
+ const i = t.target.closest("[role=tab]");
394
+ i && this.selectTab(this.tabs.indexOf(i));
395
+ });
396
+ }
397
+ connectedCallback() {
398
+ this.tablist.addEventListener("keydown", this.onKeyDown), this.tablist.addEventListener("click", this.onClick), this.selectTab(0, !1), this.tabs.forEach((t, e) => {
399
+ const i = this.tabpanels[e], n = t.getAttribute("id") || this.idPrefix + "_tab_" + e, o = i.getAttribute("id") || this.idPrefix + "_panel_" + e;
400
+ t.setAttribute("id", n), t.setAttribute("aria-controls", o), i.setAttribute("id", o), i.setAttribute("aria-labelledby", n), i.setAttribute("tabindex", "0");
401
+ });
402
+ }
403
+ disconnectedCallback() {
404
+ this.tablist.removeEventListener("keydown", this.onKeyDown), this.tablist.removeEventListener("click", this.onClick);
405
+ }
406
+ selectTab(t, e = !0) {
407
+ t < 0 ? t += this.tabs.length : t >= this.tabs.length && (t -= this.tabs.length), this.tabs.forEach((i, n) => {
408
+ n === t ? (i.setAttribute("aria-selected", "true"), i.removeAttribute("tabindex"), this.tabpanels[n].hidden = !1, e && i.focus()) : (i.setAttribute("aria-selected", "false"), i.setAttribute("tabindex", "-1"), this.tabpanels[n].hidden = !0);
409
+ });
410
+ }
411
+ get tablist() {
412
+ return this.querySelector("[role=tablist]");
413
+ }
414
+ get tabs() {
415
+ return Array.from(this.querySelectorAll("[role=tab]"));
416
+ }
417
+ get tabpanels() {
418
+ return Array.from(this.querySelectorAll("[role=tabpanel]"));
419
+ }
420
+ }
421
+ class j extends HTMLElement {
369
422
  constructor() {
370
423
  super(...arguments);
371
424
  s(this, "onInitialFocus", () => {
@@ -377,8 +430,8 @@ class U extends HTMLElement {
377
430
  const e = this.controls, i = this.controls.length, n = e.indexOf(t.target);
378
431
  if (n === -1)
379
432
  return;
380
- let a = 0;
381
- t.key === "ArrowLeft" && (a = n - 1), t.key === "ArrowRight" && (a = n + 1), t.key === "End" && (a = i - 1), a < 0 && (a = i - 1), a > i - 1 && (a = 0), this.focusControlAtIndex(a), t.preventDefault();
433
+ let o = 0;
434
+ t.key === "ArrowLeft" && (o = n - 1), t.key === "ArrowRight" && (o = n + 1), t.key === "End" && (o = i - 1), o < 0 && (o = i - 1), o > i - 1 && (o = 0), this.focusControlAtIndex(o), t.preventDefault();
382
435
  });
383
436
  }
384
437
  connectedCallback() {
@@ -393,10 +446,10 @@ class U extends HTMLElement {
393
446
  });
394
447
  }
395
448
  get controls() {
396
- return A(this);
449
+ return k(this);
397
450
  }
398
451
  }
399
- const l = class extends HTMLElement {
452
+ const u = class extends HTMLElement {
400
453
  constructor() {
401
454
  super(...arguments);
402
455
  s(this, "parent");
@@ -436,8 +489,8 @@ const l = class extends HTMLElement {
436
489
  if (this.disabled)
437
490
  return;
438
491
  const t = this.createTooltip();
439
- clearTimeout(this.timeout), this.showing || (t.hidden = !1, h(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", g(this.parent, t, {
440
- placement: this.getAttribute("placement") || l.placement,
492
+ clearTimeout(this.timeout), this.showing || (t.hidden = !1, h(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", E(this.parent, t, {
493
+ placement: this.getAttribute("placement") || u.placement,
441
494
  middleware: [L(), x()]
442
495
  }).then(({ x: e, y: i, placement: n }) => {
443
496
  Object.assign(t.style, {
@@ -447,7 +500,7 @@ const l = class extends HTMLElement {
447
500
  });
448
501
  }
449
502
  hide() {
450
- clearTimeout(this.timeout), this.showing && (this.showing = !1, d(this.tooltip).then(() => {
503
+ clearTimeout(this.timeout), this.showing && (this.showing = !1, c(this.tooltip).then(() => {
451
504
  this.tooltip && (this.tooltip.hidden = !0);
452
505
  }));
453
506
  }
@@ -456,25 +509,26 @@ const l = class extends HTMLElement {
456
509
  const e = parseInt(this.getAttribute("delay") || "");
457
510
  this.timeout = window.setTimeout(
458
511
  t.bind(this),
459
- isNaN(e) ? l.delay : e
512
+ isNaN(e) ? u.delay : e
460
513
  );
461
514
  }
462
515
  createTooltip() {
463
- return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || l.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
516
+ return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || u.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
464
517
  "mouseleave",
465
518
  this.afterDelay.bind(this, this.hide)
466
519
  ), document.body.appendChild(this.tooltip)), this.tooltip;
467
520
  }
468
521
  };
469
- let c = l;
470
- s(c, "delay", 100), s(c, "placement", "top"), s(c, "tooltipClass", "tooltip");
522
+ let d = u;
523
+ s(d, "delay", 100), s(d, "placement", "top"), s(d, "tooltipClass", "tooltip");
471
524
  export {
472
- I as AccordionElement,
473
- b as AlertsElement,
474
- P as DisclosureElement,
525
+ F as AccordionElement,
526
+ p as AlertsElement,
527
+ $ as DisclosureElement,
475
528
  f as MenuElement,
476
529
  m as ModalElement,
477
- $ as PopupElement,
478
- U as ToolbarElement,
479
- c as TooltipElement
530
+ U as PopupElement,
531
+ R as TabsElement,
532
+ j as ToolbarElement,
533
+ d as TooltipElement
480
534
  };
@@ -1,6 +1,6 @@
1
1
  export default class AccordionElement extends HTMLElement {
2
2
  connectedCallback(): void;
3
3
  disconnectedCallback(): void;
4
- private onOpen;
4
+ private onToggle;
5
5
  get required(): boolean;
6
6
  }
@@ -4,5 +4,6 @@ export { default as DisclosureElement } from './disclosure/disclosure';
4
4
  export { default as MenuElement } from './menu/menu';
5
5
  export { default as ModalElement } from './modal/modal';
6
6
  export { default as PopupElement } from './popup/popup';
7
+ export { default as TabsElement } from './tabs/tabs';
7
8
  export { default as ToolbarElement } from './toolbar/toolbar';
8
9
  export { default as TooltipElement } from './tooltip/tooltip';
@@ -0,0 +1,11 @@
1
+ export default class TabsElement extends HTMLElement {
2
+ private idPrefix;
3
+ connectedCallback(): void;
4
+ disconnectedCallback(): void;
5
+ private selectTab;
6
+ private onKeyDown;
7
+ private onClick;
8
+ private get tablist();
9
+ private get tabs();
10
+ private get tabpanels();
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inclusive-elements",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "description": "Accessible, lightweight, unstyled implementations of common UI controls.",
5
5
  "module": "dist/inclusive-elements.js",
6
6
  "type": "module",