@webority/ui-elements 0.7.7 → 0.7.8

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.
@@ -76,7 +76,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
76
76
  ];
77
77
  }
78
78
  constructor() {
79
- super(), this._value = "", this._label = "", this._optionsProp = null, this._loading = !1, this._active = -1, this._timer = null, this._reqSeq = 0, this._pendingSearch = null;
79
+ super(), this._value = "", this._label = "", this._optionsProp = null, this._loading = !1, this._active = -1, this._timer = null, this._reqSeq = 0, this._pendingSearch = null, this._typeahead = "", this._typeaheadTimer = null;
80
80
  try {
81
81
  this._internals = this.attachInternals();
82
82
  } catch {
@@ -233,7 +233,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
233
233
  }, o = () => !e.menu.hidden, s = () => {
234
234
  e.menu.hidden = !1, e.control.setAttribute("aria-expanded", "true"), e.control.classList.add("open"), t(), this._renderOptions();
235
235
  }, l = () => {
236
- e.menu.hidden = !0, e.control.setAttribute("aria-expanded", "false"), e.control.classList.remove("open"), r(-1), this._syncInput();
236
+ e.menu.hidden = !0, e.control.setAttribute("aria-expanded", "false"), e.control.classList.remove("open"), r(-1), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "", this._syncInput();
237
237
  }, u = (t) => {
238
238
  let n = t.dataset.custom === "true";
239
239
  this._value = t.dataset.value, this._label = n ? t.dataset.value : h(t.innerHTML), c(this, this._value), e.input.value = this._label, this.dispatchEvent(new CustomEvent("change", {
@@ -245,8 +245,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
245
245
  bubbles: !0,
246
246
  detail: { isCustom: !0 }
247
247
  })), l();
248
- };
249
- e.input.addEventListener("focus", () => s()), e.input.addEventListener("input", () => {
248
+ }, f = () => {
250
249
  let t = e.input.value;
251
250
  if (e.clear && (e.clear.hidden = !t), o() || s(), this._remote) {
252
251
  if (this._renderOptions(t), clearTimeout(this._timer), t.trim().length < this._minChars) {
@@ -259,18 +258,36 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
259
258
  seq: e
260
259
  }, this._timer = setTimeout(() => this._fireSearch(t, e), this._debounceMs);
261
260
  } else this._renderOptions(t);
262
- }), e.input.addEventListener("keydown", (t) => {
263
- let i = n();
261
+ }, p = () => {
262
+ clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
263
+ }, m = (t) => {
264
+ let i = n(), a = t.target?.tagName === "INPUT" || t.target?.tagName === "TEXTAREA";
264
265
  if (t.key === "ArrowDown") t.preventDefault(), o() || s(), r(Math.min(this._active + 1, i.length - 1));
265
266
  else if (t.key === "ArrowUp") t.preventDefault(), r(Math.max(this._active - 1, 0));
266
- else if (t.key === "Enter") {
267
+ else if (t.key === "Home" && o() && !a) t.preventDefault(), i.length && r(0);
268
+ else if (t.key === "End" && o() && !a) t.preventDefault(), i.length && r(i.length - 1);
269
+ else if (t.key === "PageDown" && o() && !a) {
270
+ if (t.preventDefault(), !i.length) return;
271
+ let e = this._active < 0 ? 0 : this._active;
272
+ r(Math.min(e + 8, i.length - 1));
273
+ } else if (t.key === "PageUp" && o() && !a) {
274
+ if (t.preventDefault(), !i.length) return;
275
+ let e = this._active < 0 ? 0 : this._active;
276
+ r(Math.max(e - 8, 0));
277
+ } else if (t.key === "Enter") {
267
278
  if (i[this._active]) t.preventDefault(), u(i[this._active]);
268
279
  else if (this._allowCustom) {
269
280
  let n = e.input.value.trim();
270
281
  n && !this._matchesKnownOption(n) && (t.preventDefault(), d(n));
271
282
  }
272
- } else t.key === "Escape" && l();
273
- }), e.input.addEventListener("blur", (t) => {
283
+ } else if (t.key === "Escape") l();
284
+ else if (o() && t.key.length === 1 && !t.ctrlKey && !t.metaKey && !t.altKey && t.target?.tagName !== "INPUT" && t.target?.tagName !== "TEXTAREA") {
285
+ t.preventDefault(), clearTimeout(this._typeaheadTimer), this._typeahead += t.key.toLowerCase(), this._typeaheadTimer = setTimeout(p, 500);
286
+ let e = i.findIndex((e) => e.textContent.trim().toLowerCase().startsWith(this._typeahead));
287
+ e >= 0 && r(e);
288
+ }
289
+ };
290
+ e.input.addEventListener("focus", () => s()), e.input.addEventListener("input", f), e.input.addEventListener("keydown", m), e.menu.addEventListener("keydown", m), e.input.addEventListener("blur", (t) => {
274
291
  if (!this._allowCustom || t.relatedTarget && this.contains(t.relatedTarget)) return;
275
292
  let n = e.input.value.trim();
276
293
  !n || n === this._label || this._matchesKnownOption(n) || d(n);
@@ -300,7 +317,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
300
317
  }));
301
318
  }
302
319
  _teardown() {
303
- this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this), clearTimeout(this._timer);
320
+ this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this), clearTimeout(this._timer), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
304
321
  }
305
322
  disconnectedCallback() {
306
323
  this._teardown();
@@ -343,7 +360,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
343
360
  y: e,
344
361
  m: t
345
362
  };
346
- }, w = class extends HTMLElement {
363
+ }, ee = class extends HTMLElement {
347
364
  static formAssociated = !0;
348
365
  static get observedAttributes() {
349
366
  return [
@@ -650,7 +667,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
650
667
  disconnectedCallback() {
651
668
  this._teardown();
652
669
  }
653
- }, ee = [
670
+ }, w = [
654
671
  "January",
655
672
  "February",
656
673
  "March",
@@ -663,7 +680,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
663
680
  "October",
664
681
  "November",
665
682
  "December"
666
- ], te = [
683
+ ], T = [
667
684
  "Su",
668
685
  "Mo",
669
686
  "Tu",
@@ -671,24 +688,24 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
671
688
  "Th",
672
689
  "Fr",
673
690
  "Sa"
674
- ], T = (e) => String(e).padStart(2, "0"), ne = (e, t, n) => `${e}-${T(t + 1)}-${T(n)}`, E = (e) => {
691
+ ], E = (e) => String(e).padStart(2, "0"), te = (e, t, n) => `${e}-${E(t + 1)}-${E(n)}`, D = (e) => {
675
692
  let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e || "");
676
693
  return t ? {
677
694
  y: +t[1],
678
695
  m: t[2] - 1,
679
696
  d: +t[3]
680
697
  } : null;
681
- }, D = (e) => {
682
- let t = E(e);
683
- return t ? `${T(t.d)} ${ee[t.m].slice(0, 3)} ${t.y}` : "";
684
- }, O = (e, t) => new Date(e, t + 1, 0).getDate(), k = (e, t) => {
698
+ }, O = (e) => {
699
+ let t = D(e);
700
+ return t ? `${E(t.d)} ${w[t.m].slice(0, 3)} ${t.y}` : "";
701
+ }, k = (e, t) => new Date(e, t + 1, 0).getDate(), A = (e, t) => {
685
702
  for (; t < 0;) t += 12, --e;
686
703
  for (; t > 11;) t -= 12, e += 1;
687
704
  return {
688
705
  y: e,
689
706
  m: t
690
707
  };
691
- }, re = class extends HTMLElement {
708
+ }, j = class extends HTMLElement {
692
709
  static formAssociated = !0;
693
710
  static get observedAttributes() {
694
711
  return [
@@ -747,13 +764,13 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
747
764
  text: e,
748
765
  empty: !0
749
766
  } : {
750
- text: `${D(this._start) || "Start"} – ${D(this._end) || "End"}`,
767
+ text: `${O(this._start) || "Start"} – ${O(this._end) || "End"}`,
751
768
  empty: !1
752
769
  };
753
770
  }
754
771
  render() {
755
772
  this._defaultStart === void 0 && (this._defaultStart = this.getAttribute("start") || "", this._defaultEnd = this.getAttribute("end") || "", this._start = this._defaultStart || this._start, this._end = this._defaultEnd || this._end);
756
- let e = E(this._start);
773
+ let e = D(this._start);
757
774
  e && (this._viewY = e.y, this._viewM = e.m);
758
775
  let t = this.getAttribute("size"), n = t === "sm" ? " input-sm" : t === "lg" ? " input-lg" : "", { text: r, empty: i } = this._label(), a = this.getAttribute("aria-label"), o = this.getAttribute("aria-describedby");
759
776
  this.innerHTML = `
@@ -787,24 +804,24 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
787
804
  r || (r = document.createElement("input"), r.type = "hidden", r.setAttribute("data-range-mirror", e), this.appendChild(r)), r.name = t, r.value = n || "", r.disabled = this.hasAttribute("disabled");
788
805
  }
789
806
  _limits() {
790
- let e = E(this.getAttribute("min")), t = E(this.getAttribute("max")), n = e ? new Date(e.y, e.m, e.d).getTime() : -Infinity, r = t ? new Date(t.y, t.m, t.d).getTime() : Infinity;
807
+ let e = D(this.getAttribute("min")), t = D(this.getAttribute("max")), n = e ? new Date(e.y, e.m, e.d).getTime() : -Infinity, r = t ? new Date(t.y, t.m, t.d).getTime() : Infinity;
791
808
  return (e, t, i) => {
792
809
  let a = new Date(e, t, i).getTime();
793
810
  return a < n || a > r;
794
811
  };
795
812
  }
796
813
  _monthHtml(e, t) {
797
- let n = this._firstDay(), r = (new Date(e, t, 1).getDay() - n + 7) % 7, i = O(e, t), a = this._limits(), o = te.map((e, t) => te[(t + n) % 7]).map((e) => `<span>${e}</span>`).join(""), s = (e, t, n, r) => {
798
- let i = ne(e, t, n), o = a(e, t, n);
814
+ let n = this._firstDay(), r = (new Date(e, t, 1).getDay() - n + 7) % 7, i = k(e, t), a = this._limits(), o = T.map((e, t) => T[(t + n) % 7]).map((e) => `<span>${e}</span>`).join(""), s = (e, t, n, r) => {
815
+ let i = te(e, t, n), o = a(e, t, n);
799
816
  return `<button type="button" class="${["datepicker-day", r ? "is-outside" : ""].filter(Boolean).join(" ")}" data-iso="${i}"${o ? " disabled" : ""}>${n}</button>`;
800
- }, c = "", l = k(e, t - 1), u = O(l.y, l.m);
817
+ }, c = "", l = A(e, t - 1), u = k(l.y, l.m);
801
818
  for (let e = r - 1; e >= 0; e--) c += s(l.y, l.m, u - e, !0);
802
819
  for (let n = 1; n <= i; n++) c += s(e, t, n, !1);
803
- let d = k(e, t + 1), f = (7 - (r + i) % 7) % 7;
820
+ let d = A(e, t + 1), f = (7 - (r + i) % 7) % 7;
804
821
  for (let e = 1; e <= f; e++) c += s(d.y, d.m, e, !0);
805
822
  return `
806
823
  <div class="daterange-cal">
807
- <div class="datepicker-month-label">${ee[t]} ${e}</div>
824
+ <div class="datepicker-month-label">${w[t]} ${e}</div>
808
825
  <div class="datepicker-weekdays">${o}</div>
809
826
  <div class="datepicker-grid" role="grid">${c}</div>
810
827
  </div>`;
@@ -812,7 +829,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
812
829
  _renderView() {
813
830
  let e = this.querySelector(".daterange-pop");
814
831
  if (!e) return;
815
- let t = k(this._viewY, this._viewM + 1);
832
+ let t = A(this._viewY, this._viewM + 1);
816
833
  e.innerHTML = `
817
834
  <div class="daterange-head">
818
835
  <button type="button" class="datepicker-nav-btn" data-nav="-1" aria-label="Previous month"><i class="bi bi-chevron-left" aria-hidden="true"></i></button>
@@ -838,7 +855,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
838
855
  n.classList.toggle("is-range-start", i), n.classList.toggle("is-range-end", a), n.classList.toggle("in-range", o);
839
856
  }
840
857
  let i = e.querySelector("[data-range-hint]");
841
- i && (i.textContent = this._start ? this._end ? `${D(this._start)} – ${D(this._end)}` : "Pick an end date" : "Pick a start date");
858
+ i && (i.textContent = this._start ? this._end ? `${O(this._start)} – ${O(this._end)}` : "Pick an end date" : "Pick a start date");
842
859
  }
843
860
  _position(e, t) {
844
861
  i(e, t);
@@ -860,7 +877,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
860
877
  if (!e || !t) return;
861
878
  let r = () => !t.hidden;
862
879
  this._open = () => {
863
- let r = E(this._start);
880
+ let r = D(this._start);
864
881
  if (r) this._viewY = r.y, this._viewM = r.m;
865
882
  else {
866
883
  let e = /* @__PURE__ */ new Date();
@@ -873,7 +890,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
873
890
  this._popClick = !0;
874
891
  let t = e.target.closest("[data-nav]");
875
892
  if (t) {
876
- let e = k(this._viewY, this._viewM + Number(t.dataset.nav));
893
+ let e = A(this._viewY, this._viewM + Number(t.dataset.nav));
877
894
  this._viewY = e.y, this._viewM = e.m, this._renderView();
878
895
  return;
879
896
  }
@@ -903,7 +920,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
903
920
  disconnectedCallback() {
904
921
  this._teardown();
905
922
  }
906
- }, ie = class extends HTMLElement {
923
+ }, ne = class extends HTMLElement {
907
924
  static formAssociated = !0;
908
925
  _accessibleName() {
909
926
  return this.getAttribute("aria-label") || this.getAttribute("placeholder") || "Select";
@@ -921,7 +938,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
921
938
  ];
922
939
  }
923
940
  constructor() {
924
- super(), this._values = [], this._optionsProp = null, this._active = -1;
941
+ super(), this._values = [], this._optionsProp = null, this._active = -1, this._typeahead = "", this._typeaheadTimer = null;
925
942
  try {
926
943
  this._internals = this.attachInternals();
927
944
  } catch {
@@ -994,13 +1011,13 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
994
1011
  let a = `${this.id}-listbox`;
995
1012
  this._listboxId = a, this.innerHTML = `
996
1013
  <div class="search-select${i}">
997
- <div class="input search-select-control search-select-multi" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="${A(a)}" aria-label="${A(this._accessibleName())}"${this.hasAttribute("disabled") ? " aria-disabled=\"true\"" : " tabindex=\"0\""}>
998
- ${n ? `<i class="bi bi-${A(n)} search-select-icon" aria-hidden="true"></i>` : ""}
1014
+ <div class="input search-select-control search-select-multi" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="${M(a)}" aria-label="${M(this._accessibleName())}"${this.hasAttribute("disabled") ? " aria-disabled=\"true\"" : " tabindex=\"0\""}>
1015
+ ${n ? `<i class="bi bi-${M(n)} search-select-icon" aria-hidden="true"></i>` : ""}
999
1016
  <div class="ms-chips" data-chips></div>
1000
1017
  <i class="bi bi-chevron-down search-select-caret" aria-hidden="true"></i>
1001
1018
  </div>
1002
- <div class="search-select-menu search-select-menu-fixed" role="listbox" id="${A(a)}" aria-multiselectable="true" tabindex="-1" hidden>
1003
- ${e ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${A(t)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
1019
+ <div class="search-select-menu search-select-menu-fixed" role="listbox" id="${M(a)}" aria-multiselectable="true" tabindex="-1" hidden>
1020
+ ${e ? `<div class="search-select-search"><i class="bi bi-search" aria-hidden="true"></i><input class="search-select-input" placeholder="${M(t)}" aria-autocomplete="list" /><button type="button" class="search-select-clear" aria-label="Clear search" hidden><i class="bi bi-x" aria-hidden="true"></i></button></div>` : ""}
1004
1021
  <div class="search-select-options"></div>
1005
1022
  <div class="search-select-empty" hidden>No matches</div>
1006
1023
  </div>
@@ -1014,7 +1031,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1014
1031
  e.innerHTML = `<span class="search-select-placeholder">${u(t)}</span>`;
1015
1032
  return;
1016
1033
  }
1017
- e.innerHTML = this._values.map((e) => `<span class="chip chip-sm"><span class="chip-label">${this._labelHtmlFor(e)}</span><button type="button" class="chip-remove" data-remove="${A(e)}" aria-label="Remove ${A(ae(this._labelFor(e)))}"><i class="bi bi-x" aria-hidden="true"></i></button></span>`).join(""), this._collapseChips();
1034
+ e.innerHTML = this._values.map((e) => `<span class="chip chip-sm"><span class="chip-label">${this._labelHtmlFor(e)}</span><button type="button" class="chip-remove" data-remove="${M(e)}" aria-label="Remove ${M(re(this._labelFor(e)))}"><i class="bi bi-x" aria-hidden="true"></i></button></span>`).join(""), this._collapseChips();
1018
1035
  }
1019
1036
  _collapseChips() {
1020
1037
  let e = this.querySelector("[data-chips]");
@@ -1038,11 +1055,11 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1038
1055
  let t = this.querySelector(".search-select-options"), n = this.querySelector(".search-select-empty");
1039
1056
  if (!t) return;
1040
1057
  let r = (e || "").trim().toLowerCase(), i = this._readOptions();
1041
- r && (i = i.filter((e) => ae(e.label).toLowerCase().includes(r)));
1058
+ r && (i = i.filter((e) => re(e.label).toLowerCase().includes(r)));
1042
1059
  let a = this._listboxId || `${this.id || "wui-multiselect"}-listbox`;
1043
1060
  t.innerHTML = i.map((e, t) => {
1044
1061
  let n = this._values.includes(String(e.value));
1045
- return `<button type="button" role="option" id="${A(`${a}-opt-${t}`)}" class="search-select-option${n ? " selected" : ""}" data-value="${A(e.value)}" aria-selected="${n}"><span class="ms-opt-label">${f(e)}</span><span class="ms-check"><i class="bi bi-check" aria-hidden="true"></i></span></button>`;
1062
+ return `<button type="button" role="option" id="${M(`${a}-opt-${t}`)}" class="search-select-option${n ? " selected" : ""}" data-value="${M(e.value)}" aria-selected="${n}"><span class="ms-opt-label">${f(e)}</span><span class="ms-check"><i class="bi bi-check" aria-hidden="true"></i></span></button>`;
1046
1063
  }).join(""), n && (n.hidden = i.length > 0), this._active = -1, this.querySelector(".search-select-control")?.removeAttribute("aria-activedescendant");
1047
1064
  }
1048
1065
  _wire() {
@@ -1057,7 +1074,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1057
1074
  }, p = () => !t.hidden, m = () => {
1058
1075
  s() || (t.hidden = !1, e.setAttribute("aria-expanded", "true"), e.classList.add("open"), l(), n && (n.value = "", this._renderOptions(""), n.focus()));
1059
1076
  }, h = () => {
1060
- t.hidden = !0, e.setAttribute("aria-expanded", "false"), e.classList.remove("open"), f(-1);
1077
+ t.hidden = !0, e.setAttribute("aria-expanded", "false"), e.classList.remove("open"), f(-1), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
1061
1078
  }, g = () => {
1062
1079
  c(this, this._values.join(",")), this.dispatchEvent(new Event("change", { bubbles: !0 }));
1063
1080
  }, _ = (e) => {
@@ -1083,15 +1100,36 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1083
1100
  }), o.addEventListener("mouseleave", () => f(-1)), n?.addEventListener("input", () => {
1084
1101
  this._renderOptions(n.value), r && (r.hidden = !n.value), f(-1);
1085
1102
  });
1086
- let y = (t) => {
1087
- let r = d();
1088
- t.key === "ArrowDown" ? (t.preventDefault(), f(Math.min(this._active + 1, r.length - 1))) : t.key === "ArrowUp" ? (t.preventDefault(), f(Math.max(this._active - 1, 0))) : t.key === "Enter" ? (t.preventDefault(), r[this._active] && _(r[this._active].dataset.value)) : t.key === "Escape" ? (h(), e.focus()) : t.key === "Backspace" && !n?.value && this._values.length && v(this._values[this._values.length - 1]);
1103
+ let y = () => {
1104
+ clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
1105
+ }, b = (t) => {
1106
+ let r = d(), i = t.target?.tagName === "INPUT" || t.target?.tagName === "TEXTAREA";
1107
+ if (t.key === "ArrowDown") t.preventDefault(), f(Math.min(this._active + 1, r.length - 1));
1108
+ else if (t.key === "ArrowUp") t.preventDefault(), f(Math.max(this._active - 1, 0));
1109
+ else if (t.key === "Home" && !i) t.preventDefault(), r.length && f(0);
1110
+ else if (t.key === "End" && !i) t.preventDefault(), r.length && f(r.length - 1);
1111
+ else if (t.key === "PageDown" && !i) {
1112
+ if (t.preventDefault(), !r.length) return;
1113
+ let e = this._active < 0 ? 0 : this._active;
1114
+ f(Math.min(e + 8, r.length - 1));
1115
+ } else if (t.key === "PageUp" && !i) {
1116
+ if (t.preventDefault(), !r.length) return;
1117
+ let e = this._active < 0 ? 0 : this._active;
1118
+ f(Math.max(e - 8, 0));
1119
+ } else if (t.key === "Enter") t.preventDefault(), r[this._active] && _(r[this._active].dataset.value);
1120
+ else if (t.key === "Escape") h(), e.focus();
1121
+ else if (t.key === "Backspace" && !n?.value && this._values.length) v(this._values[this._values.length - 1]);
1122
+ else if (t.key.length === 1 && !t.ctrlKey && !t.metaKey && !t.altKey && t.target?.tagName !== "INPUT" && t.target?.tagName !== "TEXTAREA") {
1123
+ t.preventDefault(), clearTimeout(this._typeaheadTimer), this._typeahead += t.key.toLowerCase(), this._typeaheadTimer = setTimeout(y, 500);
1124
+ let e = r.findIndex((e) => e.textContent.trim().toLowerCase().startsWith(this._typeahead));
1125
+ e >= 0 && f(e);
1126
+ }
1089
1127
  };
1090
- n?.addEventListener("keydown", y), r?.addEventListener("click", () => {
1128
+ n?.addEventListener("keydown", b), r?.addEventListener("click", () => {
1091
1129
  n.value = "", this._renderOptions(""), r.hidden = !0, n.focus();
1092
1130
  }), e.addEventListener("keydown", (e) => {
1093
1131
  if (p()) {
1094
- y(e);
1132
+ b(e);
1095
1133
  return;
1096
1134
  }
1097
1135
  (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") && (e.preventDefault(), m());
@@ -1104,12 +1142,12 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1104
1142
  }, this._bindGlobal();
1105
1143
  }
1106
1144
  _teardown() {
1107
- this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this);
1145
+ this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
1108
1146
  }
1109
1147
  disconnectedCallback() {
1110
1148
  this._teardown(), this._ro?.disconnect(), this._ro = null;
1111
1149
  }
1112
- }, A = (e) => String(e ?? "").replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;"), ae = (e) => String(e ?? "").replace(/<[^>]*>/g, ""), oe = /[^0-9]/g, se = /[^0-9a-zA-Z]/g, j = class extends HTMLElement {
1150
+ }, M = (e) => String(e ?? "").replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;"), re = (e) => String(e ?? "").replace(/<[^>]*>/g, ""), ie = /[^0-9]/g, ae = /[^0-9a-zA-Z]/g, N = class extends HTMLElement {
1113
1151
  static formAssociated = !0;
1114
1152
  static get observedAttributes() {
1115
1153
  return [
@@ -1140,7 +1178,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1140
1178
  this._value = this._clean(e), c(this, this._value), this._paint();
1141
1179
  }
1142
1180
  _clean(e) {
1143
- return (e == null ? "" : String(e)).replace(this.mode === "alphanumeric" ? se : oe, "").slice(0, this.length);
1181
+ return (e == null ? "" : String(e)).replace(this.mode === "alphanumeric" ? ae : ie, "").slice(0, this.length);
1144
1182
  }
1145
1183
  constructor() {
1146
1184
  super();
@@ -1220,7 +1258,7 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
1220
1258
  disconnectedCallback() {
1221
1259
  this._onSelectionChange && document.removeEventListener("selectionchange", this._onSelectionChange);
1222
1260
  }
1223
- }, M = [
1261
+ }, oe = [
1224
1262
  [
1225
1263
  "AF",
1226
1264
  "Afghanistan",
@@ -2446,56 +2484,56 @@ var l = Symbol("wui.trustedHtml"), u = (e) => String(e ?? "").replace(/&/g, "&am
2446
2484
  "Zimbabwe",
2447
2485
  "263"
2448
2486
  ]
2449
- ], N = (e) => (M.find((t) => t[0] === e) || [
2487
+ ], P = (e) => (oe.find((t) => t[0] === e) || [
2450
2488
  "",
2451
2489
  "",
2452
2490
  ""
2453
- ])[2], P = (e) => `wui-flag wui-flag-${String(e).toLowerCase()}`, F = null, I = null;
2491
+ ])[2], F = (e) => `wui-flag wui-flag-${String(e).toLowerCase()}`, I = null, se = null;
2454
2492
  function ce() {
2455
- return F ? Promise.resolve(F) : (I ||= Promise.all([import("./libphonenumber-js-BcNT8oq0.js"), import("./examples.mobile.json-BMXTGiGC.js")]).then(([e, t]) => (F = {
2493
+ return I ? Promise.resolve(I) : (se ||= Promise.all([import("./libphonenumber-js-BcNT8oq0.js"), import("./examples.mobile.json-BMXTGiGC.js")]).then(([e, t]) => (I = {
2456
2494
  AsYouType: e.AsYouType,
2457
2495
  getExampleNumber: e.getExampleNumber,
2458
2496
  isValidPhoneNumber: e.isValidPhoneNumber,
2459
2497
  examples: t.default || t
2460
- }, F)).catch(() => null), I);
2498
+ }, I)).catch(() => null), se);
2461
2499
  }
2462
2500
  function L(e, t) {
2463
- if (!F || !t) return t;
2501
+ if (!I || !t) return t;
2464
2502
  try {
2465
- return new F.AsYouType(e).input(t);
2503
+ return new I.AsYouType(e).input(t);
2466
2504
  } catch {
2467
2505
  return t;
2468
2506
  }
2469
2507
  }
2470
2508
  function R(e) {
2471
- if (!F) return null;
2509
+ if (!I) return null;
2472
2510
  try {
2473
- return F.getExampleNumber(e, F.examples)?.formatNational() || null;
2511
+ return I.getExampleNumber(e, I.examples)?.formatNational() || null;
2474
2512
  } catch {
2475
2513
  return null;
2476
2514
  }
2477
2515
  }
2478
2516
  function z(e) {
2479
- if (!F || !e) return null;
2517
+ if (!I || !e) return null;
2480
2518
  try {
2481
- return F.isValidPhoneNumber(e);
2519
+ return I.isValidPhoneNumber(e);
2482
2520
  } catch {
2483
2521
  return null;
2484
2522
  }
2485
2523
  }
2486
2524
  function le(e) {
2487
- if (!F) return null;
2525
+ if (!I) return null;
2488
2526
  try {
2489
- let t = F.getExampleNumber(e, F.examples);
2527
+ let t = I.getExampleNumber(e, I.examples);
2490
2528
  return t?.nationalNumber ? t.nationalNumber.length : null;
2491
2529
  } catch {
2492
2530
  return null;
2493
2531
  }
2494
2532
  }
2495
2533
  function B(e) {
2496
- if (!F || !e?.trim().startsWith("+")) return null;
2534
+ if (!I || !e?.trim().startsWith("+")) return null;
2497
2535
  try {
2498
- let t = new F.AsYouType();
2536
+ let t = new I.AsYouType();
2499
2537
  t.input(e.trim());
2500
2538
  let n = t.getCountry();
2501
2539
  return n ? {
@@ -2526,119 +2564,170 @@ var V = class extends HTMLElement {
2526
2564
  } catch {
2527
2565
  this._internals = null;
2528
2566
  }
2529
- this._country = "IN", this._national = "";
2567
+ this._country = "IN", this._national = "", this._active = -1, this._committedValue = "";
2530
2568
  }
2531
2569
  connectedCallback() {
2532
- this._rendered || this.render();
2570
+ if (!this._rendered) {
2571
+ this.render();
2572
+ return;
2573
+ }
2574
+ this._bindGlobal?.();
2533
2575
  }
2534
2576
  attributeChangedCallback(e, t, n) {
2535
2577
  if (e === "value") {
2536
2578
  this.value = n;
2537
2579
  return;
2538
2580
  }
2539
- this._rendered && (e === "country" && (this._country = n || "IN"), this.render());
2581
+ this._rendered && (e === "country" && (this._country = n || "IN", this._suppressCountryRender) || this.render());
2540
2582
  }
2541
2583
  formResetCallback() {
2542
2584
  this.value = this._defaultValue || "";
2543
2585
  }
2544
2586
  get value() {
2545
- return this._national ? `+${N(this._country)}${this._national}` : "";
2587
+ return this._national ? `+${P(this._country)}${this._national}` : "";
2546
2588
  }
2547
2589
  set value(e) {
2548
2590
  let t = String(e ?? "").trim(), n = B(t);
2549
2591
  if (n) this._country = n.country, this._national = n.national.replace(/[^0-9]/g, "");
2550
2592
  else if (t.startsWith("+")) {
2551
- let e = t.replace(/[^0-9]/g, ""), n = String(N(this._country));
2593
+ let e = t.replace(/[^0-9]/g, ""), n = String(P(this._country));
2552
2594
  n && e.startsWith(n) && (e = e.slice(n.length)), this._national = e;
2553
2595
  } else this._national = t.replace(/[^0-9]/g, "");
2554
- n && this.getAttribute("country") !== this._country ? this.setAttribute("country", this._country) : this._rendered && this.render(), this._syncMirror();
2596
+ n && this.getAttribute("country") !== this._country ? this.setAttribute("country", this._country) : this._rendered && this.render(), this._committedValue = this.value, this._syncMirror();
2555
2597
  }
2556
2598
  _syncMirror() {
2557
2599
  c(this, this.value);
2558
2600
  }
2601
+ _emitInput() {
2602
+ this.dispatchEvent(new Event("input", { bubbles: !0 }));
2603
+ }
2604
+ _emitChange() {
2605
+ this._committedValue = this.value, this.dispatchEvent(new Event("change", { bubbles: !0 }));
2606
+ }
2559
2607
  render() {
2560
- this._defaultValue === void 0 && (this._defaultValue = this.getAttribute("value") || "");
2608
+ this._defaultValue === void 0 && (this._defaultValue = this.getAttribute("value") || ""), this._country = this.getAttribute("country") || this._country;
2561
2609
  let e = this.getAttribute("placeholder") || R(this._country) || "Enter phone number";
2562
- this._country = this.getAttribute("country") || this._country;
2563
- let t = M.map(([e, t, n]) => `<button type="button" role="option" class="country-dropdown-item${e === this._country ? " selected" : ""}" data-iso="${e}"><span class="${P(e)}" aria-hidden="true"></span><span class="country-name-text">${t}<span class="country-code-text">+${n}</span></span></button>`).join("");
2610
+ this.id ||= `wui-phone-${Math.random().toString(36).slice(2, 9)}`;
2611
+ let t = `${this.id}-listbox`;
2612
+ this._listboxId = t;
2613
+ let n = oe.map(([e, n, r], i) => `<button type="button" role="option" id="${H(`${t}-opt-${i}`)}" class="country-dropdown-item${e === this._country ? " selected" : ""}" data-iso="${e}" aria-selected="${e === this._country}"><span class="${F(e)}" aria-hidden="true"></span><span class="country-name-text">${n}<span class="country-code-text">+${r}</span></span></button>`).join("");
2564
2614
  this.innerHTML = `
2565
2615
  <div class="phone-input-wrap">
2566
2616
  <div class="phone-country-adornment">
2567
- <button type="button" class="country-toggle" aria-haspopup="listbox" aria-expanded="false"${this.hasAttribute("disabled") ? " disabled" : ""}>
2568
- <span class="${P(this._country)}" data-flag aria-hidden="true"></span>
2617
+ <button type="button" class="country-toggle" aria-haspopup="listbox" aria-expanded="false" aria-controls="${H(t)}"${this.hasAttribute("disabled") ? " disabled" : ""}>
2618
+ <span class="${F(this._country)}" data-flag aria-hidden="true"></span>
2569
2619
  <i class="bi bi-chevron-down phone-chevron" aria-hidden="true"></i>
2570
- <span class="phone-dial" data-dial>+${N(this._country)}</span>
2620
+ <span class="phone-dial" data-dial>+${P(this._country)}</span>
2571
2621
  </button>
2572
- <div class="country-dropdown-menu" role="listbox" hidden>
2573
- <div class="dropdown-search-wrapper"><span class="dropdown-search-icon"><i class="bi bi-search" aria-hidden="true"></i></span><input type="text" class="dropdown-search-input" placeholder="Search country or code" aria-label="Search countries" /></div>
2574
- <div class="country-list-scroll">${t}<div class="country-empty" hidden>No countries found</div></div>
2622
+ <div class="country-dropdown-menu" role="listbox" id="${H(t)}" tabindex="-1" hidden>
2623
+ <div class="dropdown-search-wrapper"><span class="dropdown-search-icon"><i class="bi bi-search" aria-hidden="true"></i></span><input type="text" class="dropdown-search-input" placeholder="Search country or code" aria-label="Search countries" aria-controls="${H(t)}" aria-autocomplete="list" /></div>
2624
+ <div class="country-list-scroll">${n}<div class="country-empty" hidden>No countries found</div></div>
2575
2625
  </div>
2576
2626
  </div>
2577
2627
  <input type="tel" class="input" placeholder="${H(e)}" value="${H(L(this._country, this._national))}"${this.getAttribute("aria-label") ? ` aria-label="${H(this.getAttribute("aria-label"))}"` : ""}${this.getAttribute("aria-describedby") ? ` aria-describedby="${H(this.getAttribute("aria-describedby"))}"` : ""}${this.hasAttribute("required") ? " required aria-required=\"true\"" : ""}${this.hasAttribute("disabled") ? " disabled" : ""} />
2578
2628
  </div>
2579
2629
  <div class="field-error" data-phone-error hidden></div>`, this._rendered = !0, c(this, this.value), this._wire();
2580
2630
  }
2631
+ _itemEls() {
2632
+ return [...this.querySelectorAll(".country-dropdown-item")];
2633
+ }
2634
+ _visibleItems() {
2635
+ return this._itemEls().filter((e) => !e.hidden);
2636
+ }
2581
2637
  _wire() {
2582
2638
  this._teardown();
2583
- let e = this.querySelector(".country-toggle"), t = this.querySelector(".phone-input-wrap"), n = this.querySelector(".country-dropdown-menu"), r = this.querySelector(".dropdown-search-input"), i = this.querySelector(".country-list-scroll"), a = this.querySelector(".country-empty"), o = this.querySelector("input[type=tel]"), s = this.querySelector("[data-flag]"), c = this.querySelector("[data-dial]");
2639
+ let e = this.querySelector(".country-toggle"), t = this.querySelector(".phone-input-wrap"), n = this.querySelector(".country-dropdown-menu"), r = this.querySelector(".dropdown-search-input"), s = this.querySelector(".country-list-scroll"), c = this.querySelector(".country-empty"), l = this.querySelector("input[type=tel]"), u = this.querySelector("[data-flag]"), d = this.querySelector("[data-dial]");
2584
2640
  if (!e || !n) return;
2585
- let l = () => !n.hidden, u = () => {
2586
- let r = (t || e).getBoundingClientRect(), i = n.offsetWidth || 320, a = n.offsetHeight || 320, o = window.innerHeight - r.bottom, s = o < a + 6 && r.top > o ? r.top - a - 6 : r.bottom + 6, c = Math.min(Math.max(8, r.left), Math.max(8, window.innerWidth - i - 8));
2587
- n.style.top = `${Math.max(8, s)}px`, n.style.left = `${c}px`;
2588
- }, d = () => {
2589
- n.hidden = !1, e.setAttribute("aria-expanded", "true"), r.value = "", p(""), u(), r.focus();
2590
- }, f = () => {
2591
- n.hidden = !0, e.setAttribute("aria-expanded", "false");
2592
- };
2593
- this._reposition = () => {
2594
- l() && u();
2595
- }, window.addEventListener("scroll", this._reposition, !0), window.addEventListener("resize", this._reposition);
2596
- let p = (e) => {
2641
+ let f = () => !n.hidden, p = () => i(t || e, n), m = (e) => {
2642
+ let t = this._visibleItems();
2643
+ this._active = e;
2644
+ for (let e of this._itemEls()) e.classList.remove("is-active");
2645
+ e >= 0 && t[e] ? (t[e].classList.add("is-active"), t[e].scrollIntoView({ block: "nearest" }), r?.setAttribute("aria-activedescendant", t[e].id)) : r?.removeAttribute("aria-activedescendant");
2646
+ }, h = () => {
2647
+ n.hidden = !1, e.setAttribute("aria-expanded", "true"), r.value = "", _(""), p(), r.focus(), m(this._visibleItems().findIndex((e) => e.classList.contains("selected")));
2648
+ }, g = () => {
2649
+ n.hidden = !0, e.setAttribute("aria-expanded", "false"), m(-1);
2650
+ }, _ = (e) => {
2597
2651
  let t = e.trim().toLowerCase(), n = 0;
2598
- for (let e of i.querySelectorAll(".country-dropdown-item")) {
2652
+ for (let e of this._itemEls()) {
2599
2653
  let r = !t || e.textContent.toLowerCase().includes(t);
2600
2654
  e.hidden = !r, r && (n += 1);
2601
2655
  }
2602
- a && (a.hidden = n > 0);
2603
- }, m = (e) => {
2604
- this._country = e, this.setAttribute("country", e), s && (s.className = P(e)), c && (c.textContent = `+${N(e)}`);
2605
- for (let t of i.querySelectorAll(".country-dropdown-item")) t.classList.toggle("selected", t.dataset.iso === e);
2606
- f(), this._syncMirror(), this.dispatchEvent(new Event("change", { bubbles: !0 }));
2656
+ c && (c.hidden = n > 0);
2657
+ }, v = (e) => {
2658
+ this._country = e, this.getAttribute("country") !== e && (this._suppressCountryRender = !0, this.setAttribute("country", e), this._suppressCountryRender = !1), u && (u.className = F(e)), d && (d.textContent = `+${P(e)}`);
2659
+ for (let t of this._itemEls()) {
2660
+ let n = t.dataset.iso === e;
2661
+ t.classList.toggle("selected", n), t.setAttribute("aria-selected", String(n));
2662
+ }
2663
+ !this.getAttribute("placeholder") && l && (l.placeholder = R(e) || "Enter phone number"), l && this._national && (l.value = L(e, this._national)), g(), this._syncMirror(), this._emitChange(), l?.focus();
2664
+ }, y = (t) => {
2665
+ let n = this._visibleItems();
2666
+ if (t.key === "ArrowDown") {
2667
+ if (t.preventDefault(), !f()) {
2668
+ h();
2669
+ return;
2670
+ }
2671
+ m(Math.min(this._active + 1, n.length - 1));
2672
+ } else if (t.key === "ArrowUp") {
2673
+ if (t.preventDefault(), !f()) return;
2674
+ m(Math.max(this._active - 1, 0));
2675
+ } else t.key === "Enter" ? (t.preventDefault(), f() && n[this._active] && v(n[this._active].dataset.iso)) : t.key === "Escape" && f() && (t.preventDefault(), g(), e.focus());
2607
2676
  };
2608
- e.addEventListener("click", () => l() ? f() : d()), r.addEventListener("input", () => p(r.value)), i.addEventListener("click", (e) => {
2677
+ e.addEventListener("click", () => f() ? g() : h()), e.addEventListener("keydown", (e) => {
2678
+ if (f()) {
2679
+ y(e);
2680
+ return;
2681
+ }
2682
+ (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") && (e.preventDefault(), h());
2683
+ }), r.addEventListener("input", () => {
2684
+ _(r.value);
2685
+ let e = this._visibleItems();
2686
+ m(e.length ? 0 : -1);
2687
+ }), s.addEventListener("click", (e) => {
2609
2688
  let t = e.target.closest(".country-dropdown-item");
2610
- t && m(t.dataset.iso);
2611
- });
2612
- let h = this.querySelector("[data-phone-error]"), g = (e) => {
2613
- if (o.classList.toggle("is-invalid", e), e ? o.setAttribute("aria-invalid", "true") : o.removeAttribute("aria-invalid"), h) {
2689
+ t && v(t.dataset.iso);
2690
+ }), s.addEventListener("mousemove", (e) => {
2691
+ let t = e.target.closest(".country-dropdown-item");
2692
+ t && m(this._visibleItems().indexOf(t));
2693
+ }), s.addEventListener("mouseleave", () => m(-1)), n.addEventListener("keydown", y);
2694
+ let b = this.querySelector("[data-phone-error]"), x = (e) => {
2695
+ if (l.classList.toggle("is-invalid", e), e ? l.setAttribute("aria-invalid", "true") : l.removeAttribute("aria-invalid"), b) {
2614
2696
  if (e) {
2615
2697
  let e = R(this._country);
2616
- h.textContent = e ? `Enter a valid phone number, e.g. ${e}` : "Enter a valid phone number";
2698
+ b.textContent = e ? `Enter a valid phone number, e.g. ${e}` : "Enter a valid phone number";
2617
2699
  }
2618
- h.hidden = !e;
2700
+ b.hidden = !e;
2619
2701
  }
2620
2702
  };
2621
- o.addEventListener("input", () => {
2622
- let e = o.value.replace(/[^0-9]/g, ""), t = le(this._country);
2623
- t && e.length > t && (e = e.slice(0, t)), this._national = e;
2624
- let n = L(this._country, this._national);
2625
- o.value !== n && (o.value = n), this._syncMirror(), this.dispatchEvent(new Event("change", { bubbles: !0 })), o.classList.contains("is-invalid") && (!this._national || z(this.value) === !0) && g(!1);
2626
- }), o.addEventListener("blur", () => {
2627
- g(this._national.length > 0 && z(this.value) === !1);
2628
- }), o.addEventListener("paste", (e) => {
2703
+ l.addEventListener("input", (e) => {
2704
+ e.stopPropagation();
2705
+ let t = l.value.replace(/[^0-9]/g, ""), n = le(this._country);
2706
+ n && t.length > n && (t = t.slice(0, n)), this._national = t;
2707
+ let r = L(this._country, this._national);
2708
+ l.value !== r && (l.value = r), this._syncMirror(), this._emitInput(), l.classList.contains("is-invalid") && (!this._national || z(this.value) === !0) && x(!1);
2709
+ }), l.addEventListener("change", (e) => e.stopPropagation()), l.addEventListener("blur", () => {
2710
+ x(this._national.length > 0 && z(this.value) === !1), this.value !== this._committedValue && this._emitChange();
2711
+ }), l.addEventListener("paste", (e) => {
2629
2712
  let t = B(e.clipboardData?.getData("text"));
2630
- t && (e.preventDefault(), this._national = t.national.replace(/[^0-9]/g, ""), t.country === this._country ? o.value = L(this._country, this._national) : this.setAttribute("country", t.country), this._syncMirror(), this.dispatchEvent(new Event("change", { bubbles: !0 })), this.querySelector("input[type=tel]")?.focus());
2631
- }), this._onDocClick = (e) => {
2632
- l() && !this.contains(e.target) && f();
2633
- }, document.addEventListener("click", this._onDocClick), ce().then((e) => {
2634
- if (!(!e || !o) && (this._national && (o.value = L(this._country, this._national)), !this.getAttribute("placeholder"))) {
2713
+ t && (e.preventDefault(), this._national = t.national.replace(/[^0-9]/g, ""), t.country === this._country ? l.value = L(this._country, this._national) : this.setAttribute("country", t.country), this._syncMirror(), this._emitInput(), this._emitChange(), this.querySelector("input[type=tel]")?.focus());
2714
+ }), this._bindGlobal = () => {
2715
+ this._teardownGlobals?.(), this._onDocClick = (e) => {
2716
+ f() && !this.contains(e.target) && g();
2717
+ }, document.addEventListener("click", this._onDocClick), a(this, () => {
2718
+ f() && p();
2719
+ });
2720
+ }, this._teardownGlobals = () => {
2721
+ this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this);
2722
+ }, this._bindGlobal(), ce().then((e) => {
2723
+ if (!(!e || !l.isConnected) && (this._national && (l.value = L(this._country, this._national)), !this.getAttribute("placeholder"))) {
2635
2724
  let e = R(this._country);
2636
- e && (o.placeholder = e);
2725
+ e && (l.placeholder = e);
2637
2726
  }
2638
2727
  }), this._syncMirror();
2639
2728
  }
2640
2729
  _teardown() {
2641
- this._reposition && (window.removeEventListener("scroll", this._reposition, !0), window.removeEventListener("resize", this._reposition)), this._onDocClick && document.removeEventListener("click", this._onDocClick);
2730
+ this._teardownGlobals?.();
2642
2731
  }
2643
2732
  disconnectedCallback() {
2644
2733
  this._teardown();
@@ -2670,7 +2759,7 @@ var V = class extends HTMLElement {
2670
2759
  } catch {
2671
2760
  this._internals = null;
2672
2761
  }
2673
- this._value = "", this._optionsProp = null, this._active = -1;
2762
+ this._value = "", this._optionsProp = null, this._active = -1, this._typeahead = "", this._typeaheadTimer = null;
2674
2763
  }
2675
2764
  connectedCallback() {
2676
2765
  if (!this._rendered) {
@@ -2794,18 +2883,38 @@ var V = class extends HTMLElement {
2794
2883
  }, o = () => !e.menu.hidden, s = () => {
2795
2884
  e.menu.hidden = !1, e.control.setAttribute("aria-expanded", "true"), e.control.classList.add("open"), t(), e.search && (e.search.value = "", r(""), e.search.focus()), n(this._optionEls().findIndex((e) => e.classList.contains("selected")));
2796
2885
  }, c = () => {
2797
- e.menu.hidden = !0, e.control.setAttribute("aria-expanded", "false"), e.control.classList.remove("open"), n(-1);
2886
+ e.menu.hidden = !0, e.control.setAttribute("aria-expanded", "false"), e.control.classList.remove("open"), n(-1), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
2798
2887
  }, l = (t) => {
2799
2888
  this.value = t.dataset.value, this.dispatchEvent(new Event("change", { bubbles: !0 })), c(), e.control.focus();
2800
- }, u = (t) => {
2801
- let r = this._visible();
2802
- t.key === "ArrowDown" ? (t.preventDefault(), n(Math.min(this._active + 1, r.length - 1))) : t.key === "ArrowUp" ? (t.preventDefault(), n(Math.max(this._active - 1, 0))) : t.key === "Enter" ? (t.preventDefault(), r[this._active] && l(r[this._active])) : t.key === "Escape" && (c(), e.control.focus());
2889
+ }, u = () => {
2890
+ clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
2891
+ }, d = (t) => {
2892
+ let r = this._visible(), i = t.target?.tagName === "INPUT" || t.target?.tagName === "TEXTAREA";
2893
+ if (t.key === "ArrowDown") t.preventDefault(), n(Math.min(this._active + 1, r.length - 1));
2894
+ else if (t.key === "ArrowUp") t.preventDefault(), n(Math.max(this._active - 1, 0));
2895
+ else if (t.key === "Home" && !i) t.preventDefault(), r.length && n(0);
2896
+ else if (t.key === "End" && !i) t.preventDefault(), r.length && n(r.length - 1);
2897
+ else if (t.key === "PageDown" && !i) {
2898
+ if (t.preventDefault(), !r.length) return;
2899
+ let e = this._active < 0 ? 0 : this._active;
2900
+ n(Math.min(e + 8, r.length - 1));
2901
+ } else if (t.key === "PageUp" && !i) {
2902
+ if (t.preventDefault(), !r.length) return;
2903
+ let e = this._active < 0 ? 0 : this._active;
2904
+ n(Math.max(e - 8, 0));
2905
+ } else if (t.key === "Enter") t.preventDefault(), r[this._active] && l(r[this._active]);
2906
+ else if (t.key === "Escape") c(), e.control.focus();
2907
+ else if (t.key.length === 1 && !t.ctrlKey && !t.metaKey && !t.altKey && t.target?.tagName !== "INPUT" && t.target?.tagName !== "TEXTAREA") {
2908
+ t.preventDefault(), clearTimeout(this._typeaheadTimer), this._typeahead += t.key.toLowerCase(), this._typeaheadTimer = setTimeout(u, 500);
2909
+ let e = r.findIndex((e) => e.textContent.trim().toLowerCase().startsWith(this._typeahead));
2910
+ e >= 0 && n(e);
2911
+ }
2803
2912
  };
2804
2913
  e.reset?.addEventListener("click", (t) => {
2805
2914
  t.stopPropagation(), this.value = "", this.dispatchEvent(new Event("change", { bubbles: !0 })), e.control.focus();
2806
2915
  }), e.control.addEventListener("click", () => o() ? c() : s()), e.control.addEventListener("keydown", (e) => {
2807
2916
  if (o()) {
2808
- u(e);
2917
+ d(e);
2809
2918
  return;
2810
2919
  }
2811
2920
  (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") && (e.preventDefault(), s());
@@ -2819,7 +2928,7 @@ var V = class extends HTMLElement {
2819
2928
  r(e.search.value), n(-1);
2820
2929
  }), e.clear?.addEventListener("click", () => {
2821
2930
  e.search.value = "", r(""), e.search.focus();
2822
- }), e.menu.addEventListener("keydown", u), this._bindGlobal = () => {
2931
+ }), e.menu.addEventListener("keydown", d), this._bindGlobal = () => {
2823
2932
  this._teardown(), this._onDocClick = (e) => {
2824
2933
  o() && !this.contains(e.target) && c();
2825
2934
  }, document.addEventListener("click", this._onDocClick), a(this, () => {
@@ -2828,7 +2937,7 @@ var V = class extends HTMLElement {
2828
2937
  }, this._bindGlobal();
2829
2938
  }
2830
2939
  _teardown() {
2831
- this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this);
2940
+ this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), o(this), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
2832
2941
  }
2833
2942
  disconnectedCallback() {
2834
2943
  this._teardown();
@@ -3260,7 +3369,7 @@ var V = class extends HTMLElement {
3260
3369
  } catch {
3261
3370
  this._internals = null;
3262
3371
  }
3263
- this._value = "", this._focus = null;
3372
+ this._value = "", this._focus = null, this._typeahead = "", this._typeaheadTimer = null;
3264
3373
  }
3265
3374
  connectedCallback() {
3266
3375
  if (!this._rendered) {
@@ -3348,6 +3457,26 @@ var V = class extends HTMLElement {
3348
3457
  this._focus = n, this._renderOptions();
3349
3458
  break;
3350
3459
  }
3460
+ case "Home":
3461
+ if (e.preventDefault(), !t.length) return;
3462
+ this._focus = 0, this._renderOptions();
3463
+ break;
3464
+ case "End":
3465
+ if (e.preventDefault(), !t.length) return;
3466
+ this._focus = t.length - 1, this._renderOptions();
3467
+ break;
3468
+ case "PageUp": {
3469
+ if (e.preventDefault(), !t.length) return;
3470
+ let n = this._focus == null || this._focus < 0 ? 0 : this._focus;
3471
+ this._focus = Math.max(n - 8, 0), this._renderOptions();
3472
+ break;
3473
+ }
3474
+ case "PageDown": {
3475
+ if (e.preventDefault(), !t.length) return;
3476
+ let n = this._focus == null || this._focus < 0 ? 0 : this._focus;
3477
+ this._focus = Math.min(n + 8, t.length - 1), this._renderOptions();
3478
+ break;
3479
+ }
3351
3480
  case "Enter":
3352
3481
  case " ":
3353
3482
  e.preventDefault(), t[this._focus] && (this.value = t[this._focus].dataset.hm, this.dispatchEvent(new Event("change", { bubbles: !0 })), this._close());
@@ -3355,7 +3484,13 @@ var V = class extends HTMLElement {
3355
3484
  case "Escape":
3356
3485
  this._close();
3357
3486
  break;
3358
- default:
3487
+ default: if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
3488
+ e.preventDefault(), clearTimeout(this._typeaheadTimer), this._typeahead += e.key.toLowerCase(), this._typeaheadTimer = setTimeout(() => {
3489
+ this._typeahead = "", this._typeaheadTimer = null;
3490
+ }, 500);
3491
+ let n = t.findIndex((e) => e.textContent.trim().toLowerCase().startsWith(this._typeahead));
3492
+ n >= 0 && (this._focus = n, this._renderOptions());
3493
+ }
3359
3494
  }
3360
3495
  }
3361
3496
  _wire() {
@@ -3368,7 +3503,7 @@ var V = class extends HTMLElement {
3368
3503
  let n = t.querySelector(".is-selected");
3369
3504
  n ? this._focus = [...t.querySelectorAll(".timepicker-option")].indexOf(n) : this._focus = 0, this._renderOptions(), t.querySelector("[tabindex=\"0\"]")?.focus();
3370
3505
  }, this._close = () => {
3371
- t.hidden = !0, e.setAttribute("aria-expanded", "false"), e.focus();
3506
+ t.hidden = !0, e.setAttribute("aria-expanded", "false"), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "", e.focus();
3372
3507
  }, e.addEventListener("click", () => n() ? this._close() : this._open()), e.addEventListener("keydown", (e) => {
3373
3508
  (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && (e.preventDefault(), n() || this._open());
3374
3509
  }), t.addEventListener("click", (e) => {
@@ -3389,7 +3524,7 @@ var V = class extends HTMLElement {
3389
3524
  }, this._bindGlobal(), this._syncFormValue();
3390
3525
  }
3391
3526
  _teardown() {
3392
- this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), this._onDocKey &&= (document.removeEventListener("keydown", this._onDocKey), null), o(this);
3527
+ this._onDocClick &&= (document.removeEventListener("click", this._onDocClick), null), this._onDocKey &&= (document.removeEventListener("keydown", this._onDocKey), null), o(this), clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null, this._typeahead = "";
3393
3528
  }
3394
3529
  disconnectedCallback() {
3395
3530
  this._teardown();
@@ -3462,8 +3597,8 @@ var Q = (e, t) => {
3462
3597
  typeof customElements < "u" && !customElements.get(e) && customElements.define(e, t);
3463
3598
  };
3464
3599
  function $() {
3465
- Q("wui-select", U), Q("wui-phone", V), Q("wui-datepicker", w), Q("wui-date-range", re), Q("wui-slider", G), Q("wui-timepicker", me), Q("wui-autocomplete", p), Q("wui-multiselect", ie), Q("wui-taginput", de), Q("wui-otp", j), Q("wui-status-icon", n);
3600
+ Q("wui-select", U), Q("wui-phone", V), Q("wui-datepicker", ee), Q("wui-date-range", j), Q("wui-slider", G), Q("wui-timepicker", me), Q("wui-autocomplete", p), Q("wui-multiselect", ne), Q("wui-taginput", de), Q("wui-otp", N), Q("wui-status-icon", n);
3466
3601
  }
3467
3602
  $();
3468
3603
  //#endregion
3469
- export { he as DEFAULT_IMAGE_ACCEPT, ge as DEFAULT_MAX_SIZE_MB, t as STATUS_TONES, p as WuiAutocomplete, w as WuiDatePicker, re as WuiDateRange, ie as WuiMultiSelect, j as WuiOtp, V as WuiPhone, U as WuiSelect, G as WuiSlider, n as WuiStatusIcon, de as WuiTagInput, me as WuiTimePicker, Se as acceptLabel, $ as defineWeborityElements, be as isImageFile, xe as isImageOnlyAccept, Ce as matchesAccept, we as validateFile };
3604
+ export { he as DEFAULT_IMAGE_ACCEPT, ge as DEFAULT_MAX_SIZE_MB, t as STATUS_TONES, p as WuiAutocomplete, ee as WuiDatePicker, j as WuiDateRange, ne as WuiMultiSelect, N as WuiOtp, V as WuiPhone, U as WuiSelect, G as WuiSlider, n as WuiStatusIcon, de as WuiTagInput, me as WuiTimePicker, Se as acceptLabel, $ as defineWeborityElements, be as isImageFile, xe as isImageOnlyAccept, Ce as matchesAccept, we as validateFile };