@danielgindi/selectbox 2.0.11 → 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,
@@ -1402,6 +1408,8 @@ class SelectBox {
1402
1408
 
1403
1409
  if (p.dropList.hasFocusedItem()) {
1404
1410
  p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
1411
+ } else if (!p.multi && this.getValue() !== undefined) {
1412
+ p.dropList.setFocusedItemByValue(this.getValue());
1405
1413
  }
1406
1414
 
1407
1415
  return this;
@@ -1467,9 +1475,9 @@ class SelectBox {
1467
1475
 
1468
1476
  p.isLoadingMode = isLoadingMode;
1469
1477
 
1470
- if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
1478
+ if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
1471
1479
  this.closeList();
1472
- } else if (!p.isLoadingMode && document.activeElement &&
1480
+ } else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement &&
1473
1481
  ((p.multi || p.searchable) && p.input.contains(document.activeElement) ||
1474
1482
  (!p.multi && !p.searchable) && p.el.contains(document.activeElement))) {
1475
1483
  this.openList();
@@ -1486,6 +1494,41 @@ class SelectBox {
1486
1494
  return this._p.isLoadingMode;
1487
1495
  }
1488
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
+
1489
1532
  /**
1490
1533
  * Sets the appropriate direction for the selectbox
1491
1534
  * @param {'ltr'|'rtl'|'auto'} direction
@@ -1859,8 +1902,12 @@ class SelectBox {
1859
1902
  p.el.classList.add(`${p.baseClassName}__closed_list`);
1860
1903
 
1861
1904
  if (!p.multi) {
1862
- this._setInputText('');
1905
+ if (p.clearInputWhen.includes('single_close'))
1906
+ this._setInputText('');
1863
1907
  this._scheduleSync('render_base');
1908
+ } else {
1909
+ if (p.clearInputWhen.includes('multi_close'))
1910
+ this._setInputText('');
1864
1911
  }
1865
1912
 
1866
1913
  this._trigger('close');
@@ -1916,7 +1963,7 @@ class SelectBox {
1916
1963
 
1917
1964
  if (p.showSelection) {
1918
1965
  if (checked) {
1919
- if (dropList.itemCount() === 1) {
1966
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
1920
1967
  this._setInputText('');
1921
1968
  }
1922
1969
 
@@ -2186,8 +2233,6 @@ class SelectBox {
2186
2233
 
2187
2234
  p.filterTerm = p.input.value.trim();
2188
2235
  p.dropList?.setSearchTerm(p.filterTerm, true);
2189
-
2190
- this._trigger('search', { value: p.input.value });
2191
2236
  })
2192
2237
  .add(p.input, 'click.dropdown', () => {
2193
2238
  if (p.disabled) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "2.0.11",
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",
package/vue/DropList.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <span v-show="false" />
2
+ <span v-show="false" />
3
3
  </template>
4
4
 
5
5
  <script>
package/vue/SelectBox.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <span ref="el" />
2
+ <span ref="el" />
3
3
  </template>
4
4
 
5
5
  <script>