@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.es6.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
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -1325,7 +1325,14 @@ class DropList {
1325
1325
  * @returns {DropList}
1326
1326
  */
1327
1327
  setNoResultsText(noResultsText) {
1328
- this._p.noResultsText = noResultsText;
1328
+ const p = this._p;
1329
+
1330
+ p.noResultsText = noResultsText;
1331
+
1332
+ if (p.hasNoResultsItem) {
1333
+ p.virtualListHelper.refreshItemAt(0).render();
1334
+ }
1335
+
1329
1336
  return this;
1330
1337
  }
1331
1338
 
@@ -3420,6 +3427,8 @@ const inputBackbufferCssProps = [
3420
3427
  * @property {function(items: DropList.ItemBase[], term: string):(DropList.ItemBase[]|null)} [filterFn]
3421
3428
  * @property {function(name: string, ...args)} [on]
3422
3429
  * @property {boolean} [isLoadingMode]
3430
+ * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
3431
+ * @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>
3423
3432
  * */
3424
3433
  const defaultOptions = {
3425
3434
  el: null,
@@ -3454,6 +3463,8 @@ const defaultOptions = {
3454
3463
  selectedValues: undefined,
3455
3464
  value: undefined,
3456
3465
  isLoadingMode: false,
3466
+ closeListWhenLoading: true,
3467
+ clearInputWhen: ['single_close', 'multi_select_single'],
3457
3468
  };
3458
3469
 
3459
3470
  /**
@@ -3559,6 +3570,8 @@ class SelectBox {
3559
3570
  mitt: mitt(),
3560
3571
 
3561
3572
  isLoadingMode: !!o.isLoadingMode,
3573
+ closeListWhenLoading: !!o.closeListWhenLoading,
3574
+ clearInputWhen: Array.isArray(o.clearInputWhen) ? o.clearInputWhen.slice(0) : [],
3562
3575
 
3563
3576
  items: [],
3564
3577
  itemsChanged: true,
@@ -4705,6 +4718,8 @@ class SelectBox {
4705
4718
 
4706
4719
  if (p.dropList.hasFocusedItem()) {
4707
4720
  p.dropList.setFocusedItemAtIndex(p.dropList.getFocusedItemIndex());
4721
+ } else if (!p.multi && this.getValue() !== undefined) {
4722
+ p.dropList.setFocusedItemByValue(this.getValue());
4708
4723
  }
4709
4724
 
4710
4725
  return this;
@@ -4770,9 +4785,9 @@ class SelectBox {
4770
4785
 
4771
4786
  p.isLoadingMode = isLoadingMode;
4772
4787
 
4773
- if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
4788
+ if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
4774
4789
  this.closeList();
4775
- } else if (!p.isLoadingMode && document.activeElement &&
4790
+ } else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement &&
4776
4791
  ((p.multi || p.searchable) && p.input.contains(document.activeElement) ||
4777
4792
  (!p.multi && !p.searchable) && p.el.contains(document.activeElement))) {
4778
4793
  this.openList();
@@ -4789,6 +4804,41 @@ class SelectBox {
4789
4804
  return this._p.isLoadingMode;
4790
4805
  }
4791
4806
 
4807
+ /**
4808
+ * Sets whether to close the list when loading mode is enabled
4809
+ * @param {boolean} closeListWhenLoading
4810
+ * @returns {SelectBox}
4811
+ */
4812
+ setCloseListWhenLoading(closeListWhenLoading) {
4813
+ this._p.closeListWhenLoading = closeListWhenLoading;
4814
+ return this;
4815
+ }
4816
+
4817
+ /**
4818
+ * @returns {boolean}
4819
+ */
4820
+ getCloseListWhenLoading() {
4821
+ return this._p.closeListWhenLoading;
4822
+ }
4823
+
4824
+ /**
4825
+ * Sets when to clear the input field
4826
+ * @param {string[]} clearInputWhen
4827
+ * @returns {SelectBox}
4828
+ */
4829
+ setClearInputWhen(clearInputWhen) {
4830
+ this._p.clearInputWhen = Array.isArray(clearInputWhen) ? clearInputWhen.slice(0) : [];
4831
+ return this;
4832
+ }
4833
+
4834
+ /**
4835
+ * Retrieves the settings for when to clear the input field
4836
+ * @returns {string[]}
4837
+ */
4838
+ getClearInputWhen() {
4839
+ return this._p.clearInputWhen;
4840
+ }
4841
+
4792
4842
  /**
4793
4843
  * Sets the appropriate direction for the selectbox
4794
4844
  * @param {'ltr'|'rtl'|'auto'} direction
@@ -5162,8 +5212,12 @@ class SelectBox {
5162
5212
  p.el.classList.add(`${p.baseClassName}__closed_list`);
5163
5213
 
5164
5214
  if (!p.multi) {
5165
- this._setInputText('');
5215
+ if (p.clearInputWhen.includes('single_close'))
5216
+ this._setInputText('');
5166
5217
  this._scheduleSync('render_base');
5218
+ } else {
5219
+ if (p.clearInputWhen.includes('multi_close'))
5220
+ this._setInputText('');
5167
5221
  }
5168
5222
 
5169
5223
  this._trigger('close');
@@ -5219,7 +5273,7 @@ class SelectBox {
5219
5273
 
5220
5274
  if (p.showSelection) {
5221
5275
  if (checked) {
5222
- if (dropList.itemCount() === 1) {
5276
+ if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
5223
5277
  this._setInputText('');
5224
5278
  }
5225
5279
 
@@ -5489,8 +5543,6 @@ class SelectBox {
5489
5543
 
5490
5544
  p.filterTerm = p.input.value.trim();
5491
5545
  p.dropList?.setSearchTerm(p.filterTerm, true);
5492
-
5493
- this._trigger('search', { value: p.input.value });
5494
5546
  })
5495
5547
  .add(p.input, 'click.dropdown', () => {
5496
5548
  if (p.disabled) return;