@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/dist/lib.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.12
2
+ * @danielgindi/selectbox 2.0.13
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -7550,7 +7550,14 @@
7550
7550
  * @returns {DropList}
7551
7551
  */
7552
7552
  setNoResultsText(noResultsText) {
7553
- this._p.noResultsText = noResultsText;
7553
+ const p = this._p;
7554
+
7555
+ p.noResultsText = noResultsText;
7556
+
7557
+ if (p.hasNoResultsItem) {
7558
+ p.virtualListHelper.refreshItemAt(0).render();
7559
+ }
7560
+
7554
7561
  return this;
7555
7562
  }
7556
7563
 
@@ -9907,6 +9914,8 @@
9907
9914
  * @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
9908
9915
  * @property {function(name: string, ...args)} [on]
9909
9916
  * @property {boolean} [isLoadingMode]
9917
+ * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
9918
+ * @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>
9910
9919
  * */
9911
9920
  const defaultOptions = {
9912
9921
  el: null,
@@ -9940,7 +9949,9 @@
9940
9949
  items: [],
9941
9950
  selectedValues: undefined,
9942
9951
  value: undefined,
9943
- isLoadingMode: false
9952
+ isLoadingMode: false,
9953
+ closeListWhenLoading: true,
9954
+ clearInputWhen: ['single_close', 'multi_select_single']
9944
9955
  };
9945
9956
 
9946
9957
  /**
@@ -10046,6 +10057,8 @@
10046
10057
  mitt: mitt(),
10047
10058
 
10048
10059
  isLoadingMode: !!o.isLoadingMode,
10060
+ closeListWhenLoading: !!o.closeListWhenLoading,
10061
+ clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
10049
10062
 
10050
10063
  items: [],
10051
10064
  itemsChanged: true,
@@ -11259,9 +11272,9 @@
11259
11272
 
11260
11273
  p.isLoadingMode = isLoadingMode;
11261
11274
 
11262
- if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
11275
+ if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
11263
11276
  this.closeList();
11264
- } else if (!p.isLoadingMode && document.activeElement && (
11277
+ } else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement && (
11265
11278
  (p.multi || p.searchable) && p.input.contains(document.activeElement) ||
11266
11279
  !p.multi && !p.searchable && p.el.contains(document.activeElement))) {
11267
11280
  this.openList();
@@ -11278,6 +11291,41 @@
11278
11291
  return this._p.isLoadingMode;
11279
11292
  }
11280
11293
 
11294
+ /**
11295
+ * Sets whether to close the list when loading mode is enabled
11296
+ * @param {boolean} closeListWhenLoading
11297
+ * @returns {SelectBox}
11298
+ */
11299
+ setCloseListWhenLoading(closeListWhenLoading) {
11300
+ this._p.closeListWhenLoading = closeListWhenLoading;
11301
+ return this;
11302
+ }
11303
+
11304
+ /**
11305
+ * @returns {boolean}
11306
+ */
11307
+ getCloseListWhenLoading() {
11308
+ return this._p.closeListWhenLoading;
11309
+ }
11310
+
11311
+ /**
11312
+ * Sets when to clear the input field
11313
+ * @param {string[]} clearInputWhen
11314
+ * @returns {SelectBox}
11315
+ */
11316
+ setClearInputWhen(clearInputWhen) {
11317
+ this._p.clearInputWhen = Array.isArray(clearInputWhen) ? clearInputWhen.slice(0) : [];
11318
+ return this;
11319
+ }
11320
+
11321
+ /**
11322
+ * Retrieves the settings for when to clear the input field
11323
+ * @returns {string[]}
11324
+ */
11325
+ getClearInputWhen() {
11326
+ return this._p.clearInputWhen;
11327
+ }
11328
+
11281
11329
  /**
11282
11330
  * Sets the appropriate direction for the selectbox
11283
11331
  * @param {'ltr'|'rtl'|'auto'} direction
@@ -11651,8 +11699,12 @@
11651
11699
  p.el.classList.add("".concat(p.baseClassName, "__closed_list"));
11652
11700
 
11653
11701
  if (!p.multi) {
11702
+ if (p.clearInputWhen.includes('single_close'))
11654
11703
  this._setInputText('');
11655
11704
  this._scheduleSync('render_base');
11705
+ } else {
11706
+ if (p.clearInputWhen.includes('multi_close'))
11707
+ this._setInputText('');
11656
11708
  }
11657
11709
 
11658
11710
  this._trigger('close');
@@ -11708,7 +11760,7 @@
11708
11760
 
11709
11761
  if (p.showSelection) {
11710
11762
  if (checked) {
11711
- if (dropList.itemCount() === 1) {
11763
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
11712
11764
  this._setInputText('');
11713
11765
  }
11714
11766
 
@@ -11978,8 +12030,6 @@
11978
12030
 
11979
12031
  p.filterTerm = p.input.value.trim();
11980
12032
  (_p$dropList9 = p.dropList) === null || _p$dropList9 === void 0 || _p$dropList9.setSearchTerm(p.filterTerm, true);
11981
-
11982
- this._trigger('search', { value: p.input.value });
11983
12033
  }).
11984
12034
  add(p.input, 'click.dropdown', () => {
11985
12035
  if (p.disabled) return;