@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/dist/lib.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.11
2
+ * @danielgindi/selectbox 2.0.13
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -7554,7 +7554,14 @@ class DropList {
7554
7554
  * @returns {DropList}
7555
7555
  */
7556
7556
  setNoResultsText(noResultsText) {
7557
- this._p.noResultsText = noResultsText;
7557
+ const p = this._p;
7558
+
7559
+ p.noResultsText = noResultsText;
7560
+
7561
+ if (p.hasNoResultsItem) {
7562
+ p.virtualListHelper.refreshItemAt(0).render();
7563
+ }
7564
+
7558
7565
  return this;
7559
7566
  }
7560
7567
 
@@ -9911,6 +9918,8 @@ const inputBackbufferCssProps = [
9911
9918
  * @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
9912
9919
  * @property {function(name: string, ...args)} [on]
9913
9920
  * @property {boolean} [isLoadingMode]
9921
+ * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
9922
+ * @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>
9914
9923
  * */
9915
9924
  const defaultOptions = {
9916
9925
  el: null,
@@ -9944,7 +9953,9 @@ const defaultOptions = {
9944
9953
  items: [],
9945
9954
  selectedValues: undefined,
9946
9955
  value: undefined,
9947
- isLoadingMode: false
9956
+ isLoadingMode: false,
9957
+ closeListWhenLoading: true,
9958
+ clearInputWhen: ['single_close', 'multi_select_single']
9948
9959
  };
9949
9960
 
9950
9961
  /**
@@ -10050,6 +10061,8 @@ class SelectBox {
10050
10061
  mitt: mitt(),
10051
10062
 
10052
10063
  isLoadingMode: !!o.isLoadingMode,
10064
+ closeListWhenLoading: !!o.closeListWhenLoading,
10065
+ clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
10053
10066
 
10054
10067
  items: [],
10055
10068
  itemsChanged: true,
@@ -11196,6 +11209,8 @@ class SelectBox {
11196
11209
 
11197
11210
  if (p.dropList.hasFocusedItem()) {
11198
11211
  p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
11212
+ } else if (!p.multi && this.getValue() !== undefined) {
11213
+ p.dropList.setFocusedItemByValue(this.getValue());
11199
11214
  }
11200
11215
 
11201
11216
  return this;
@@ -11261,9 +11276,9 @@ class SelectBox {
11261
11276
 
11262
11277
  p.isLoadingMode = isLoadingMode;
11263
11278
 
11264
- if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
11279
+ if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
11265
11280
  this.closeList();
11266
- } else if (!p.isLoadingMode && document.activeElement && (
11281
+ } else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement && (
11267
11282
  (p.multi || p.searchable) && p.input.contains(document.activeElement) ||
11268
11283
  !p.multi && !p.searchable && p.el.contains(document.activeElement))) {
11269
11284
  this.openList();
@@ -11280,6 +11295,41 @@ class SelectBox {
11280
11295
  return this._p.isLoadingMode;
11281
11296
  }
11282
11297
 
11298
+ /**
11299
+ * Sets whether to close the list when loading mode is enabled
11300
+ * @param {boolean} closeListWhenLoading
11301
+ * @returns {SelectBox}
11302
+ */
11303
+ setCloseListWhenLoading(closeListWhenLoading) {
11304
+ this._p.closeListWhenLoading = closeListWhenLoading;
11305
+ return this;
11306
+ }
11307
+
11308
+ /**
11309
+ * @returns {boolean}
11310
+ */
11311
+ getCloseListWhenLoading() {
11312
+ return this._p.closeListWhenLoading;
11313
+ }
11314
+
11315
+ /**
11316
+ * Sets when to clear the input field
11317
+ * @param {string[]} clearInputWhen
11318
+ * @returns {SelectBox}
11319
+ */
11320
+ setClearInputWhen(clearInputWhen) {
11321
+ this._p.clearInputWhen = Array.isArray(clearInputWhen) ? clearInputWhen.slice(0) : [];
11322
+ return this;
11323
+ }
11324
+
11325
+ /**
11326
+ * Retrieves the settings for when to clear the input field
11327
+ * @returns {string[]}
11328
+ */
11329
+ getClearInputWhen() {
11330
+ return this._p.clearInputWhen;
11331
+ }
11332
+
11283
11333
  /**
11284
11334
  * Sets the appropriate direction for the selectbox
11285
11335
  * @param {'ltr'|'rtl'|'auto'} direction
@@ -11653,8 +11703,12 @@ class SelectBox {
11653
11703
  p.el.classList.add("".concat(p.baseClassName, "__closed_list"));
11654
11704
 
11655
11705
  if (!p.multi) {
11706
+ if (p.clearInputWhen.includes('single_close'))
11656
11707
  this._setInputText('');
11657
11708
  this._scheduleSync('render_base');
11709
+ } else {
11710
+ if (p.clearInputWhen.includes('multi_close'))
11711
+ this._setInputText('');
11658
11712
  }
11659
11713
 
11660
11714
  this._trigger('close');
@@ -11710,7 +11764,7 @@ class SelectBox {
11710
11764
 
11711
11765
  if (p.showSelection) {
11712
11766
  if (checked) {
11713
- if (dropList.itemCount() === 1) {
11767
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
11714
11768
  this._setInputText('');
11715
11769
  }
11716
11770
 
@@ -11980,8 +12034,6 @@ class SelectBox {
11980
12034
 
11981
12035
  p.filterTerm = p.input.value.trim();
11982
12036
  (_p$dropList9 = p.dropList) === null || _p$dropList9 === void 0 || _p$dropList9.setSearchTerm(p.filterTerm, true);
11983
-
11984
- this._trigger('search', { value: p.input.value });
11985
12037
  }).
11986
12038
  add(p.input, 'click.dropdown', () => {
11987
12039
  if (p.disabled) return;