inclusive-elements 0.5.4 → 0.5.5

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.
@@ -1,9 +1,9 @@
1
1
  var l = Object.defineProperty;
2
- var p = (o, s, t) => s in o ? l(o, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[s] = t;
3
- var e = (o, s, t) => (p(o, typeof s != "symbol" ? s + "" : s, t), t);
4
- import { autoUpdate as u, computePosition as c, shift as v, flip as m } from "@floating-ui/dom";
5
- import { hello as b, goodbye as f } from "hello-goodbye";
6
- const n = class n extends HTMLElement {
2
+ var u = (n, s, t) => s in n ? l(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
+ var e = (n, s, t) => (u(n, typeof s != "symbol" ? s + "" : s, t), t);
4
+ import { autoUpdate as p, computePosition as c, shift as v, flip as m } from "@floating-ui/dom";
5
+ import { hello as f, goodbye as b } from "hello-goodbye";
6
+ const o = class o extends HTMLElement {
7
7
  constructor() {
8
8
  super(...arguments);
9
9
  e(this, "parent");
@@ -13,20 +13,20 @@ const n = class n extends HTMLElement {
13
13
  e(this, "showing", !1);
14
14
  e(this, "cleanup");
15
15
  e(this, "prevInnerHTML");
16
- e(this, "tabPressed", !1);
16
+ e(this, "focusKeyPressed", !1);
17
17
  e(this, "onMouseEnter", () => {
18
18
  window.matchMedia("(hover: hover) and (pointer: fine)").matches && this.afterDelay(this.show);
19
19
  });
20
20
  e(this, "onFocus", () => {
21
- this.tabPressed && this.show();
21
+ this.focusKeyPressed && this.show();
22
22
  });
23
23
  e(this, "onMouseLeave", this.afterDelay.bind(this, this.hide));
24
24
  e(this, "onBlur", this.hide.bind(this));
25
25
  e(this, "onKeyDown", (t) => {
26
- t.key === "Tab" && (this.tabPressed = !0), t.key === "Escape" && this.hide();
26
+ this.isFocusTriggerKey(t.key) && (this.focusKeyPressed = !0), t.key === "Escape" && this.hide();
27
27
  });
28
28
  e(this, "onKeyUp", (t) => {
29
- t.key === "Tab" && (this.tabPressed = !1);
29
+ this.isFocusTriggerKey(t.key) && (this.focusKeyPressed = !1);
30
30
  });
31
31
  }
32
32
  connectedCallback() {
@@ -46,16 +46,19 @@ const n = class n extends HTMLElement {
46
46
  set disabled(t) {
47
47
  t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
48
48
  }
49
+ isFocusTriggerKey(t) {
50
+ return t === "Tab" || t === "ArrowUp" || t === "ArrowDown" || t === "ArrowLeft" || t === "ArrowRight";
51
+ }
49
52
  show() {
50
53
  var i;
51
54
  if (this.disabled)
52
55
  return;
53
56
  const t = this.createTooltip();
54
- clearTimeout(this.timeout), this.showing || (t.hidden = !1, b(t), this.showing = !0), this.innerHTML !== this.prevInnerHTML && (this.prevInnerHTML = t.innerHTML = this.innerHTML), t.style.position = "absolute", (i = this.cleanup) == null || i.call(this), this.cleanup = u(
57
+ clearTimeout(this.timeout), this.showing || (t.hidden = !1, f(t), this.showing = !0), this.innerHTML !== this.prevInnerHTML && (this.prevInnerHTML = t.innerHTML = this.innerHTML), t.style.position = "absolute", (i = this.cleanup) == null || i.call(this), this.cleanup = p(
55
58
  this.parent,
56
59
  t,
57
60
  () => c(this.parent, t, {
58
- placement: this.getAttribute("placement") || n.placement,
61
+ placement: this.getAttribute("placement") || o.placement,
59
62
  middleware: [v(), m()]
60
63
  }).then(({ x: h, y: a, placement: d }) => {
61
64
  Object.assign(t.style, {
@@ -67,7 +70,7 @@ const n = class n extends HTMLElement {
67
70
  }
68
71
  hide() {
69
72
  var t;
70
- clearTimeout(this.timeout), (t = this.cleanup) == null || t.call(this), this.showing && (this.showing = !1, this.tooltip && f(this.tooltip).then(() => {
73
+ clearTimeout(this.timeout), (t = this.cleanup) == null || t.call(this), this.showing && (this.showing = !1, this.tooltip && b(this.tooltip).then(() => {
71
74
  this.tooltip && (this.tooltip.hidden = !0);
72
75
  }), this.dispatchEvent(new Event("close")));
73
76
  }
@@ -76,18 +79,18 @@ const n = class n extends HTMLElement {
76
79
  const i = parseInt(this.getAttribute("delay") || "");
77
80
  this.timeout = window.setTimeout(
78
81
  t.bind(this),
79
- isNaN(i) ? n.delay : i
82
+ isNaN(i) ? o.delay : i
80
83
  );
81
84
  }
82
85
  createTooltip() {
83
86
  return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
84
87
  "mouseleave",
85
88
  this.afterDelay.bind(this, this.hide)
86
- ), document.body.appendChild(this.tooltip)), this.tooltip.className = this.getAttribute("tooltip-class") || n.tooltipClass, this.tooltip;
89
+ ), document.body.appendChild(this.tooltip)), this.tooltip.className = this.getAttribute("tooltip-class") || o.tooltipClass, this.tooltip;
87
90
  }
88
91
  };
89
- e(n, "delay", 100), e(n, "placement", "top"), e(n, "tooltipClass", "tooltip");
90
- let r = n;
92
+ e(o, "delay", 100), e(o, "placement", "top"), e(o, "tooltipClass", "tooltip");
93
+ let r = o;
91
94
  export {
92
95
  r as default
93
96
  };
@@ -1,6 +1,6 @@
1
- var c = Object.defineProperty;
2
- var u = (r, e, t) => e in r ? c(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var n = (r, e, t) => (u(r, typeof e != "symbol" ? e + "" : e, t), t);
1
+ var h = Object.defineProperty;
2
+ var u = (s, i, t) => i in s ? h(s, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[i] = t;
3
+ var n = (s, i, t) => (u(s, typeof i != "symbol" ? i + "" : i, t), t);
4
4
  import { isFocusable as l } from "tabbable";
5
5
  const a = class a extends HTMLElement {
6
6
  constructor() {
@@ -9,19 +9,27 @@ const a = class a extends HTMLElement {
9
9
  n(this, "searchTimeout");
10
10
  n(this, "onKeyDown", (t) => {
11
11
  if (!this.hidden) {
12
- if (t.key === "ArrowUp") {
12
+ if (this.horizontal && t.key === "ArrowLeft") {
13
13
  this.navigate(-1), t.preventDefault();
14
14
  return;
15
15
  }
16
- if (t.key === "ArrowDown") {
16
+ if (this.horizontal && t.key === "ArrowRight") {
17
17
  this.navigate(1), t.preventDefault();
18
18
  return;
19
19
  }
20
+ if (t.key === "ArrowUp") {
21
+ this.horizontal ? this.focusItemAtIndex(0) : this.navigate(-1), t.preventDefault();
22
+ return;
23
+ }
24
+ if (t.key === "ArrowDown") {
25
+ this.horizontal ? this.focusItemAtIndex(this.items.length - 1) : this.navigate(1), t.preventDefault();
26
+ return;
27
+ }
20
28
  t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
21
29
  this.search = "";
22
- }, a.searchDelay), this.items.some((s) => {
23
- var i;
24
- return ((i = s.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (s.focus(), !0) : !1;
30
+ }, a.searchDelay), this.items.some((e) => {
31
+ var r;
32
+ return ((r = e.textContent) == null ? void 0 : r.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
25
33
  }));
26
34
  }
27
35
  });
@@ -39,15 +47,21 @@ const a = class a extends HTMLElement {
39
47
  this.querySelectorAll("[role^=menuitem]")
40
48
  ).filter((t) => l(t));
41
49
  }
50
+ get horizontal() {
51
+ return this.getAttribute("aria-orientation") === "horizontal";
52
+ }
42
53
  navigate(t) {
43
- var o;
44
- const s = this.items;
45
- let i = (document.activeElement instanceof HTMLElement ? s.indexOf(document.activeElement) : -1) + t;
46
- i < 0 && (i = s.length - 1), i >= s.length && (i = 0), (o = s[i]) == null || o.focus();
54
+ const e = this.items;
55
+ let r = (document.activeElement instanceof HTMLElement ? e.indexOf(document.activeElement) : -1) + t;
56
+ r < 0 && (r = e.length - 1), r >= e.length && (r = 0), this.focusItemAtIndex(r);
57
+ }
58
+ focusItemAtIndex(t) {
59
+ var e;
60
+ (e = this.items[t]) == null || e.focus();
47
61
  }
48
62
  };
49
63
  n(a, "searchDelay", 800);
50
- let h = a;
64
+ let o = a;
51
65
  export {
52
- h as default
66
+ o as default
53
67
  };
@@ -5,6 +5,8 @@ export default class MenuElement extends HTMLElement {
5
5
  connectedCallback(): void;
6
6
  disconnectedCallback(): void;
7
7
  private get items();
8
+ private get horizontal();
8
9
  private onKeyDown;
9
10
  private navigate;
11
+ private focusItemAtIndex;
10
12
  }
@@ -9,7 +9,7 @@ export default class TooltipElement extends HTMLElement {
9
9
  private showing;
10
10
  private cleanup?;
11
11
  private prevInnerHTML?;
12
- private tabPressed;
12
+ private focusKeyPressed;
13
13
  private onMouseEnter;
14
14
  private onFocus;
15
15
  private onMouseLeave;
@@ -20,6 +20,7 @@ export default class TooltipElement extends HTMLElement {
20
20
  set disabled(val: boolean);
21
21
  private onKeyDown;
22
22
  private onKeyUp;
23
+ private isFocusTriggerKey;
23
24
  show(): void;
24
25
  hide(): void;
25
26
  private afterDelay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inclusive-elements",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Accessible, lightweight, unstyled implementations of common UI controls.",
5
5
  "module": "dist/inclusive-elements.js",
6
6
  "type": "module",