@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.cjs.js +58 -8
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +58 -8
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +58 -8
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/DropList.js +8 -1
- package/lib/SelectBox.js +49 -6
- package/package.json +1 -1
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 2.0.
|
|
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
|
|
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,
|
|
@@ -4772,9 +4785,9 @@ class SelectBox {
|
|
|
4772
4785
|
|
|
4773
4786
|
p.isLoadingMode = isLoadingMode;
|
|
4774
4787
|
|
|
4775
|
-
if (p.isLoadingMode && p.items.length === 0 && this.isListOpen()) {
|
|
4788
|
+
if (p.isLoadingMode && p.closeListWhenLoading && p.items.length === 0 && this.isListOpen()) {
|
|
4776
4789
|
this.closeList();
|
|
4777
|
-
} else if (!p.isLoadingMode && document.activeElement &&
|
|
4790
|
+
} else if (!p.isLoadingMode && p.closeListWhenLoading && document.activeElement &&
|
|
4778
4791
|
((p.multi || p.searchable) && p.input.contains(document.activeElement) ||
|
|
4779
4792
|
(!p.multi && !p.searchable) && p.el.contains(document.activeElement))) {
|
|
4780
4793
|
this.openList();
|
|
@@ -4791,6 +4804,41 @@ class SelectBox {
|
|
|
4791
4804
|
return this._p.isLoadingMode;
|
|
4792
4805
|
}
|
|
4793
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
|
+
|
|
4794
4842
|
/**
|
|
4795
4843
|
* Sets the appropriate direction for the selectbox
|
|
4796
4844
|
* @param {'ltr'|'rtl'|'auto'} direction
|
|
@@ -5164,8 +5212,12 @@ class SelectBox {
|
|
|
5164
5212
|
p.el.classList.add(`${p.baseClassName}__closed_list`);
|
|
5165
5213
|
|
|
5166
5214
|
if (!p.multi) {
|
|
5167
|
-
|
|
5215
|
+
if (p.clearInputWhen.includes('single_close'))
|
|
5216
|
+
this._setInputText('');
|
|
5168
5217
|
this._scheduleSync('render_base');
|
|
5218
|
+
} else {
|
|
5219
|
+
if (p.clearInputWhen.includes('multi_close'))
|
|
5220
|
+
this._setInputText('');
|
|
5169
5221
|
}
|
|
5170
5222
|
|
|
5171
5223
|
this._trigger('close');
|
|
@@ -5221,7 +5273,7 @@ class SelectBox {
|
|
|
5221
5273
|
|
|
5222
5274
|
if (p.showSelection) {
|
|
5223
5275
|
if (checked) {
|
|
5224
|
-
if (dropList.itemCount() === 1) {
|
|
5276
|
+
if (dropList.itemCount() === 1 && p.clearInputWhen.includes('multi_select_single')) {
|
|
5225
5277
|
this._setInputText('');
|
|
5226
5278
|
}
|
|
5227
5279
|
|
|
@@ -5491,8 +5543,6 @@ class SelectBox {
|
|
|
5491
5543
|
|
|
5492
5544
|
p.filterTerm = p.input.value.trim();
|
|
5493
5545
|
p.dropList?.setSearchTerm(p.filterTerm, true);
|
|
5494
|
-
|
|
5495
|
-
this._trigger('search', { value: p.input.value });
|
|
5496
5546
|
})
|
|
5497
5547
|
.add(p.input, 'click.dropdown', () => {
|
|
5498
5548
|
if (p.disabled) return;
|