slim-select 4.2.3 → 4.3.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.
@@ -151,7 +151,7 @@ var u = 768, d = class {
151
151
  modal;
152
152
  modalTitle;
153
153
  constructor(e) {
154
- e ||= {}, this.id = "ss-" + h(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
154
+ e ||= {}, this.id = "ss-" + h(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 ? typeof window > "u" || window.innerWidth >= 768 : e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
155
155
  }
156
156
  };
157
157
  //#endregion
@@ -598,6 +598,7 @@ var O = class {
598
598
  classes;
599
599
  positionObserver = null;
600
600
  positionObserverRaf = 0;
601
+ lastObservedContentHeight = -1;
601
602
  overflowShiftRaf = 0;
602
603
  modalElements = null;
603
604
  modalSessionActive = null;
@@ -942,6 +943,9 @@ var O = class {
942
943
  announce(e) {
943
944
  this.settings.showSearch && (this.content.status.textContent = e);
944
945
  }
946
+ repositionOpenContent() {
947
+ this.settings.isOpen && !this.isModalViewActive() && this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
948
+ }
945
949
  moveContent() {
946
950
  if (!this.isModalViewActive()) {
947
951
  if (this.settings.contentPosition === "relative") {
@@ -960,21 +964,27 @@ var O = class {
960
964
  }
961
965
  }
962
966
  startPositionTracking() {
963
- this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), !(typeof ResizeObserver > "u") && (this.positionObserver = new ResizeObserver(() => {
964
- this.settings.isOpen && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
965
- this.moveContent();
967
+ this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), typeof ResizeObserver < "u" && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
968
+ if (!this.settings.isOpen) return;
969
+ let t = !1, n = !1;
970
+ for (let r of e) if (r.target === this.content.main) {
971
+ let e = r.contentRect.height;
972
+ e !== this.lastObservedContentHeight && (this.lastObservedContentHeight = e, t = !0);
973
+ } else n = !0;
974
+ (t || n) && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
975
+ n ? this.moveContent() : this.repositionOpenContent();
966
976
  }));
967
977
  }), this.observePositionTargets()));
968
978
  }
969
979
  stopPositionTracking() {
970
- cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.cancelOverflowShift();
980
+ cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.lastObservedContentHeight = -1, this.cancelOverflowShift();
971
981
  }
972
982
  observePositionTargets() {
973
983
  if (!this.positionObserver) return;
974
984
  let e = /* @__PURE__ */ new Set(), t = (t) => {
975
- !t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
985
+ t && !e.has(t) && (e.add(t), this.positionObserver.observe(t));
976
986
  };
977
- t(this.main.main);
987
+ t(this.main.main), t(this.content.main);
978
988
  let n = this.main.main.parentElement, r = this.settings.contentLocation;
979
989
  for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
980
990
  }
@@ -1103,12 +1113,12 @@ var O = class {
1103
1113
  renderError(e) {
1104
1114
  this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1105
1115
  let t = document.createElement("div");
1106
- this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
1116
+ this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t), this.repositionOpenContent();
1107
1117
  }
1108
1118
  renderSearching() {
1109
1119
  this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1110
1120
  let e = document.createElement("div");
1111
- this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
1121
+ this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText), this.repositionOpenContent();
1112
1122
  }
1113
1123
  renderOptions(e) {
1114
1124
  if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
@@ -1118,7 +1128,7 @@ var O = class {
1118
1128
  let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
1119
1129
  e.innerHTML = t, this.announce(t);
1120
1130
  } else e.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
1121
- this.content.list.appendChild(e);
1131
+ this.content.list.appendChild(e), this.repositionOpenContent();
1122
1132
  return;
1123
1133
  }
1124
1134
  this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new A({
@@ -1164,7 +1174,7 @@ var O = class {
1164
1174
  i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), t.appendChild(i);
1165
1175
  let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1166
1176
  i.appendChild(o), n.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(t, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (n) => {
1167
- n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen));
1177
+ n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)), this.repositionOpenContent();
1168
1178
  }), a.appendChild(t);
1169
1179
  }
1170
1180
  e.appendChild(r);
@@ -1172,7 +1182,7 @@ var O = class {
1172
1182
  }
1173
1183
  n instanceof A && t.appendChild(this.option(n));
1174
1184
  }
1175
- this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState();
1185
+ this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1176
1186
  }
1177
1187
  canFilterOptionsInPlace() {
1178
1188
  return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
@@ -1193,7 +1203,7 @@ var O = class {
1193
1203
  let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
1194
1204
  o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
1195
1205
  }
1196
- this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1206
+ this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1197
1207
  }
1198
1208
  setOptionsListFullData(e) {
1199
1209
  let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof A ? [e] : e.options.map((e) => new A(e))).flat();
@@ -1265,7 +1275,7 @@ var O = class {
1265
1275
  let a = e.has(t);
1266
1276
  a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
1267
1277
  }
1268
- !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1278
+ !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1269
1279
  }
1270
1280
  createSelectAllControl(e, t = !1) {
1271
1281
  let n = document.createElement("div");
@@ -1438,7 +1448,7 @@ var O = class {
1438
1448
  this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
1439
1449
  return;
1440
1450
  }
1441
- t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1451
+ t === "auto" ? this.content.main.style.minWidth = e.width + "px" : t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1442
1452
  }
1443
1453
  cancelOverflowShift() {
1444
1454
  this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
@@ -1479,7 +1489,7 @@ var O = class {
1479
1489
  updateDeselectAll() {
1480
1490
  if (!this.store || !this.settings) return;
1481
1491
  let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.isAtMinSelected(), a = this.main.deselect.main, o = this.classes.hide;
1482
- r && !(n && !t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1492
+ r && (!n || t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1483
1493
  }
1484
1494
  };
1485
1495
  //#endregion
@@ -1986,10 +1996,10 @@ var R = class {
1986
1996
  }), this.globalEvents = new O({
1987
1997
  onDocumentClick: this.documentClick.bind(this),
1988
1998
  onWindowResize: () => {
1989
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1999
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1990
2000
  },
1991
2001
  onWindowScroll: () => {
1992
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
2002
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1993
2003
  },
1994
2004
  onVisibilityChange: () => {
1995
2005
  document.hidden && this.close({
@@ -2054,7 +2064,7 @@ var R = class {
2054
2064
  source: "api",
2055
2065
  selectionChanged: !1
2056
2066
  }) {
2057
- !this.settings.isOpen || this.settings.alwaysOpen || this.lifecycle.requestClose(e).then((e) => {
2067
+ this.settings.isOpen && !this.settings.alwaysOpen && this.lifecycle.requestClose(e).then((e) => {
2058
2068
  e && (this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen));
2059
2069
  });
2060
2070
  }