inclusive-elements 0.3.3 → 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,10 +70,8 @@ const w = class extends HTMLElement {
69
70
  });
70
71
  return;
71
72
  }
72
- k(this.children, () => {
73
- d(t, {
74
- finish: () => this.removeChild(t)
75
- });
73
+ A(this.children, () => {
74
+ c(t).then(() => this.removeChild(t));
76
75
  }), this.clearTimeout(t);
77
76
  }
78
77
  clear() {
@@ -104,12 +103,12 @@ const w = class extends HTMLElement {
104
103
  this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
105
104
  }
106
105
  };
107
- let b = w;
108
- s(b, "duration", 1e4);
109
- function C(o) {
110
- 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;
111
110
  }
112
- class P extends HTMLElement {
111
+ class $ extends HTMLElement {
113
112
  constructor() {
114
113
  super(...arguments);
115
114
  s(this, "onButtonClick", (t) => {
@@ -138,12 +137,10 @@ class P extends HTMLElement {
138
137
  t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
139
138
  }
140
139
  wasOpened() {
141
- 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"));
142
141
  }
143
142
  wasClosed() {
144
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), d(this.content, {
145
- finish: () => this.content.hidden = !0
146
- }), 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"));
147
144
  }
148
145
  get button() {
149
146
  return this.querySelector("button, [role=button]");
@@ -152,7 +149,7 @@ class P extends HTMLElement {
152
149
  return this.children[1];
153
150
  }
154
151
  }
155
- const y = class extends HTMLElement {
152
+ const g = class extends HTMLElement {
156
153
  constructor() {
157
154
  super(...arguments);
158
155
  s(this, "search", "");
@@ -169,7 +166,7 @@ const y = class extends HTMLElement {
169
166
  }
170
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(() => {
171
168
  this.search = "";
172
- }, y.searchDelay), this.items.some((e) => {
169
+ }, g.searchDelay), this.items.some((e) => {
173
170
  var i;
174
171
  return ((i = e.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
175
172
  }));
@@ -196,9 +193,9 @@ const y = class extends HTMLElement {
196
193
  i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
197
194
  }
198
195
  };
199
- let f = y;
196
+ let f = g;
200
197
  s(f, "searchDelay", 800);
201
- const u = class extends HTMLElement {
198
+ const l = class extends HTMLElement {
202
199
  constructor() {
203
200
  super();
204
201
  s(this, "focusTrap");
@@ -211,8 +208,8 @@ const u = class extends HTMLElement {
211
208
  const e = this.attachShadow({ mode: "open" });
212
209
  e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
213
210
  var i;
214
- this.hasAttribute("static") ? (i = u.attention) == null || i.call(u, e.children[1]) : this.close();
215
- }), 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, {
216
213
  escapeDeactivates: !1,
217
214
  allowOutsideClick: !0,
218
215
  preventScroll: !0
@@ -222,9 +219,9 @@ const u = class extends HTMLElement {
222
219
  return ["open"];
223
220
  }
224
221
  connectedCallback() {
225
- var t, e, i, n, a, E;
226
- 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) => {
227
- 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());
228
225
  }), this.open && this.wasOpened();
229
226
  }
230
227
  disconnectedCallback() {
@@ -251,9 +248,7 @@ const u = class extends HTMLElement {
251
248
  }
252
249
  wasClosed() {
253
250
  var t;
254
- (t = this.focusTrap) == null || t.deactivate(), d(this, {
255
- finish: () => this.hidden = !0
256
- }), this.dispatchEvent(new Event("close"));
251
+ (t = this.focusTrap) == null || t.deactivate(), c(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
257
252
  }
258
253
  get backdrop() {
259
254
  var t;
@@ -263,7 +258,7 @@ const u = class extends HTMLElement {
263
258
  return this.firstElementChild;
264
259
  }
265
260
  };
266
- let m = u;
261
+ let m = l;
267
262
  s(m, "attention", (t) => t.animate(
268
263
  [
269
264
  { transform: "scale(1)" },
@@ -272,7 +267,7 @@ s(m, "attention", (t) => t.animate(
272
267
  ],
273
268
  300
274
269
  ));
275
- class $ extends HTMLElement {
270
+ class U extends HTMLElement {
276
271
  constructor() {
277
272
  super();
278
273
  s(this, "cleanup");
@@ -281,7 +276,7 @@ class $ extends HTMLElement {
281
276
  });
282
277
  s(this, "onButtonKeyDown", (t) => {
283
278
  var e;
284
- 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());
285
280
  });
286
281
  s(this, "onKeyDown", (t) => {
287
282
  t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
@@ -328,12 +323,12 @@ class $ extends HTMLElement {
328
323
  this.button,
329
324
  this.content,
330
325
  () => {
331
- g(this.button, this.content, {
326
+ E(this.button, this.content, {
332
327
  placement: this.getAttribute("placement") || "bottom",
333
328
  middleware: [
334
329
  L(),
335
330
  x(),
336
- K({
331
+ O({
337
332
  apply: ({ availableWidth: e, availableHeight: i }) => {
338
333
  Object.assign(this.content.style, {
339
334
  maxWidth: "",
@@ -358,11 +353,7 @@ class $ extends HTMLElement {
358
353
  }
359
354
  wasClosed() {
360
355
  var t;
361
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), d(this.backdrop, {
362
- finish: () => this.backdrop.hidden = !0
363
- }), d(this.content, {
364
- finish: () => this.content.hidden = !0
365
- }), 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")));
366
357
  }
367
358
  get backdrop() {
368
359
  var t;
@@ -375,7 +366,59 @@ class $ extends HTMLElement {
375
366
  return this.children[1];
376
367
  }
377
368
  }
378
- 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 {
379
422
  constructor() {
380
423
  super(...arguments);
381
424
  s(this, "onInitialFocus", () => {
@@ -387,8 +430,8 @@ class U extends HTMLElement {
387
430
  const e = this.controls, i = this.controls.length, n = e.indexOf(t.target);
388
431
  if (n === -1)
389
432
  return;
390
- let a = 0;
391
- 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();
392
435
  });
393
436
  }
394
437
  connectedCallback() {
@@ -403,10 +446,10 @@ class U extends HTMLElement {
403
446
  });
404
447
  }
405
448
  get controls() {
406
- return A(this);
449
+ return k(this);
407
450
  }
408
451
  }
409
- const l = class extends HTMLElement {
452
+ const u = class extends HTMLElement {
410
453
  constructor() {
411
454
  super(...arguments);
412
455
  s(this, "parent");
@@ -446,8 +489,8 @@ const l = class extends HTMLElement {
446
489
  if (this.disabled)
447
490
  return;
448
491
  const t = this.createTooltip();
449
- 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, {
450
- 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,
451
494
  middleware: [L(), x()]
452
495
  }).then(({ x: e, y: i, placement: n }) => {
453
496
  Object.assign(t.style, {
@@ -457,10 +500,8 @@ const l = class extends HTMLElement {
457
500
  });
458
501
  }
459
502
  hide() {
460
- clearTimeout(this.timeout), this.showing && (this.showing = !1, d(this.tooltip, {
461
- finish: () => {
462
- this.tooltip && (this.tooltip.hidden = !0);
463
- }
503
+ clearTimeout(this.timeout), this.showing && (this.showing = !1, c(this.tooltip).then(() => {
504
+ this.tooltip && (this.tooltip.hidden = !0);
464
505
  }));
465
506
  }
466
507
  afterDelay(t) {
@@ -468,25 +509,26 @@ const l = class extends HTMLElement {
468
509
  const e = parseInt(this.getAttribute("delay") || "");
469
510
  this.timeout = window.setTimeout(
470
511
  t.bind(this),
471
- isNaN(e) ? l.delay : e
512
+ isNaN(e) ? u.delay : e
472
513
  );
473
514
  }
474
515
  createTooltip() {
475
- 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(
476
517
  "mouseleave",
477
518
  this.afterDelay.bind(this, this.hide)
478
519
  ), document.body.appendChild(this.tooltip)), this.tooltip;
479
520
  }
480
521
  };
481
- let c = l;
482
- 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");
483
524
  export {
484
- I as AccordionElement,
485
- b as AlertsElement,
486
- P as DisclosureElement,
525
+ F as AccordionElement,
526
+ p as AlertsElement,
527
+ $ as DisclosureElement,
487
528
  f as MenuElement,
488
529
  m as ModalElement,
489
- $ as PopupElement,
490
- U as ToolbarElement,
491
- c as TooltipElement
530
+ U as PopupElement,
531
+ R as TabsElement,
532
+ j as ToolbarElement,
533
+ d as TooltipElement
492
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.3",
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",
@@ -18,17 +18,17 @@
18
18
  "release": "release-it"
19
19
  },
20
20
  "dependencies": {
21
- "@floating-ui/dom": "^1.2.4",
21
+ "@floating-ui/dom": "^1.2.5",
22
22
  "focus-trap": "^6.9.4",
23
- "hello-goodbye": "^0.1.1",
23
+ "hello-goodbye": "^0.2.0",
24
24
  "tabbable": "^5.3.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@release-it/conventional-changelog": "^5.1.1",
28
- "prettier": "^2.8.4",
29
- "release-it": "^15.9.0",
28
+ "prettier": "^2.8.6",
29
+ "release-it": "^15.9.1",
30
30
  "typescript": "^5.0.2",
31
- "vite": "^4.2.0"
31
+ "vite": "^4.2.1"
32
32
  },
33
33
  "release-it": {
34
34
  "git": {