@danielgindi/selectbox 2.0.12 → 2.0.13

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/lib/DropList.js CHANGED
@@ -1297,7 +1297,14 @@ class DropList {
1297
1297
  * @returns {DropList}
1298
1298
  */
1299
1299
  setNoResultsText(noResultsText) {
1300
- this._p.noResultsText = noResultsText;
1300
+ const p = this._p;
1301
+
1302
+ p.noResultsText = noResultsText;
1303
+
1304
+ if (p.hasNoResultsItem) {
1305
+ p.virtualListHelper.refreshItemAt(0).render();
1306
+ }
1307
+
1301
1308
  return this;
1302
1309
  }
1303
1310
 
package/lib/SelectBox.js CHANGED
@@ -117,6 +117,8 @@ const inputBackbufferCssProps = [
117
117
  * @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
118
118
  * @property {function(name: string, ...args)} [on]
119
119
  * @property {boolean} [isLoadingMode]
120
+ * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
121
+ * @property {string[]} [clearInputWhen=['single_close','multi_select_single']] clear input box when closing the droplist or selecting <code>['single_close', 'multi_close', 'multi_select_single']</code>
120
122
  * */
121
123
  const defaultOptions = {
122
124
  el: null,
@@ -151,6 +153,8 @@ const defaultOptions = {
151
153
  selectedValues: undefined,
152
154
  value: undefined,
153
155
  isLoadingMode: false,
156
+ closeListWhenLoading: true,
157
+ clearInputWhen: ['single_close', 'multi_select_single'],
154
158
  };
155
159
 
156
160
  /**
@@ -256,6 +260,8 @@ class SelectBox {
256
260
  mitt: mitt(),
257
261
 
258
262
  isLoadingMode: !!o.isLoadingMode,
263
+ closeListWhenLoading: !!o.closeListWhenLoading,
264
+ clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
259
265
 
260
266
  items: [],
261
267
  itemsChanged: true,
@@ -1469,9 +1475,9 @@ class SelectBox {
1469
1475
 
1470
1476
  p.isLoadingMode = isLoadingMode;
1471
1477
 
1472
- if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
1478
+ if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
1473
1479
  this.closeList();
1474
- } else if (!p.isLoadingMode && document.activeElement &&
1480
+ } else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement &&
1475
1481
  ((p.multi || p.searchable) && p.input.contains(document.activeElement) ||
1476
1482
  (!p.multi && !p.searchable) && p.el.contains(document.activeElement))) {
1477
1483
  this.openList();
@@ -1488,6 +1494,41 @@ class SelectBox {
1488
1494
  return this._p.isLoadingMode;
1489
1495
  }
1490
1496
 
1497
+ /**
1498
+ * Sets whether to close the list when loading mode is enabled
1499
+ * @param {boolean} closeListWhenLoading
1500
+ * @returns {SelectBox}
1501
+ */
1502
+ setCloseListWhenLoading(closeListWhenLoading) {
1503
+ this._p.closeListWhenLoading = closeListWhenLoading;
1504
+ return this;
1505
+ }
1506
+
1507
+ /**
1508
+ * @returns {boolean}
1509
+ */
1510
+ getCloseListWhenLoading() {
1511
+ return this._p.closeListWhenLoading;
1512
+ }
1513
+
1514
+ /**
1515
+ * Sets when to clear the input field
1516
+ * @param {string[]} clearInputWhen
1517
+ * @returns {SelectBox}
1518
+ */
1519
+ setClearInputWhen(clearInputWhen) {
1520
+ this._p.clearInputWhen = Array.isArray(clearInputWhen) ? clearInputWhen.slice(0) : [];
1521
+ return this;
1522
+ }
1523
+
1524
+ /**
1525
+ * Retrieves the settings for when to clear the input field
1526
+ * @returns {string[]}
1527
+ */
1528
+ getClearInputWhen() {
1529
+ return this._p.clearInputWhen;
1530
+ }
1531
+
1491
1532
  /**
1492
1533
  * Sets the appropriate direction for the selectbox
1493
1534
  * @param {'ltr'|'rtl'|'auto'} direction
@@ -1861,8 +1902,12 @@ class SelectBox {
1861
1902
  p.el.classList.add(`${p.baseClassName}__closed_list`);
1862
1903
 
1863
1904
  if (!p.multi) {
1864
- this._setInputText('');
1905
+ if (p.clearInputWhen.includes('single_close'))
1906
+ this._setInputText('');
1865
1907
  this._scheduleSync('render_base');
1908
+ } else {
1909
+ if (p.clearInputWhen.includes('multi_close'))
1910
+ this._setInputText('');
1866
1911
  }
1867
1912
 
1868
1913
  this._trigger('close');
@@ -1918,7 +1963,7 @@ class SelectBox {
1918
1963
 
1919
1964
  if (p.showSelection) {
1920
1965
  if (checked) {
1921
- if (dropList.itemCount() === 1) {
1966
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
1922
1967
  this._setInputText('');
1923
1968
  }
1924
1969
 
@@ -2188,8 +2233,6 @@ class SelectBox {
2188
2233
 
2189
2234
  p.filterTerm = p.input.value.trim();
2190
2235
  p.dropList?.setSearchTerm(p.filterTerm, true);
2191
-
2192
- this._trigger('search', { value: p.input.value });
2193
2236
  })
2194
2237
  .add(p.input, 'click.dropdown', () => {
2195
2238
  if (p.disabled) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",