@danielgindi/selectbox 2.0.3 → 2.0.5

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.3
2
+ * @danielgindi/selectbox 2.0.5
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -680,7 +680,8 @@ class DropList {
680
680
  const p = this._p;
681
681
 
682
682
  if (this.hasFocusedItem() && p.multi) {
683
- let item = p.items[p.focusItemIndex];
683
+ const items = p.filteredItems ?? p.items;
684
+ let item = items[p.focusItemIndex];
684
685
  if (item._nocheck || item._nointeraction) return this;
685
686
 
686
687
  item._checked = !item._checked;
@@ -748,7 +749,7 @@ class DropList {
748
749
  const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
749
750
 
750
751
  let isMulti = p.multi;
751
- let items = p.items;
752
+ const items = p.items;
752
753
 
753
754
  if (atIndex == null || atIndex < 0 || atIndex >= p.items.length) {
754
755
  atIndex = -1;
@@ -1213,11 +1214,10 @@ class DropList {
1213
1214
  if (!Array.isArray(filteredItems)) {
1214
1215
  if (term) {
1215
1216
  const matcher = new RegExp(escapeRegex(term), 'i');
1216
- const labelProp = p.labelProp;
1217
1217
 
1218
1218
  filteredItems = p.items.filter(x => {
1219
1219
  if (!filterGroups && x._group) return true;
1220
- return matcher.test(x[labelProp]);
1220
+ return matcher.test(x.label);
1221
1221
  });
1222
1222
  } else {
1223
1223
  filteredItems = null;
@@ -1258,7 +1258,7 @@ class DropList {
1258
1258
  p.filteredItems = null;
1259
1259
  }
1260
1260
 
1261
- this.needsRefilter = false;
1261
+ p.needsRefilter = false;
1262
1262
 
1263
1263
  const items = p.filteredItems ?? p.items;
1264
1264
  p.hasNoResultsItem = items.length === 0 && !!p.noResultsText;
@@ -1279,11 +1279,17 @@ class DropList {
1279
1279
  return this;
1280
1280
  }
1281
1281
 
1282
- getFilteredItemCount() {
1282
+ rushRefilter() {
1283
1283
  const p = this._p;
1284
-
1285
1284
  if (p.needsRefilter)
1286
1285
  this._refilterItems();
1286
+ return this;
1287
+ }
1288
+
1289
+ getFilteredItemCount() {
1290
+ const p = this._p;
1291
+
1292
+ this.rushRefilter();
1287
1293
 
1288
1294
  if (p.filteredItems)
1289
1295
  return p.filteredItems.length;
@@ -1485,6 +1491,8 @@ class DropList {
1485
1491
 
1486
1492
  // Calculate virtual viewport size
1487
1493
  if (p.virtualListHelper.isVirtual()) {
1494
+ // Avoid extremely high size which will cause laying out the whole list
1495
+ menuEl.style.height = Math.min(el.clientHeight, document.body.clientHeight) + 'px';
1488
1496
  p.virtualListHelper.render();
1489
1497
  }
1490
1498
 
@@ -1729,6 +1737,8 @@ class DropList {
1729
1737
  setCheckedValues(values) {
1730
1738
  const p = this._p;
1731
1739
 
1740
+ this.rushRefilter();
1741
+
1732
1742
  let groupIndexes = [];
1733
1743
 
1734
1744
  for (let i = 0, count = p.items.length; i < count; i++) {
@@ -1792,7 +1802,7 @@ class DropList {
1792
1802
 
1793
1803
  excludeGroups = excludeGroups && p.groupCount > 0;
1794
1804
 
1795
- let items = [];
1805
+ const items = [];
1796
1806
 
1797
1807
  for (let i = 0, count = p.items.length; i < count; i++) {
1798
1808
  let item = p.items[i];
@@ -1833,9 +1843,7 @@ class DropList {
1833
1843
  }
1834
1844
  });
1835
1845
 
1836
- if (p.needsRefilter) {
1837
- this._refilterItems();
1838
- }
1846
+ this.rushRefilter();
1839
1847
 
1840
1848
  const el = p.el;
1841
1849
  el.style.position = 'absolute';
@@ -2043,6 +2051,8 @@ class DropList {
2043
2051
  setFocusedItemAtIndex(itemIndex) {
2044
2052
  const p = this._p;
2045
2053
 
2054
+ this.rushRefilter();
2055
+
2046
2056
  if (p.filteredItems) {
2047
2057
  const item = p.items[itemIndex];
2048
2058
  itemIndex = p.items.indexOf(item);
@@ -2240,6 +2250,8 @@ class DropList {
2240
2250
  setSingleSelectedItemAtIndex(itemIndex) {
2241
2251
  const p = this._p;
2242
2252
 
2253
+ this.rushRefilter();
2254
+
2243
2255
  let itemEl = null;
2244
2256
 
2245
2257
  if (itemIndex > -1 && !p.items[itemIndex]._nointeraction) {
@@ -2999,7 +3011,7 @@ class DropList {
2999
3011
  let affectedItems = 0;
3000
3012
 
3001
3013
  if (p.autoCheckGroupChildren) {
3002
- let items = p.filteredItems ?? p.items;
3014
+ const items = p.filteredItems ?? p.items;
3003
3015
  let groupIndex = items.indexOf(item);
3004
3016
 
3005
3017
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
@@ -3042,7 +3054,7 @@ class DropList {
3042
3054
  affectedItems: affectedItems,
3043
3055
  });
3044
3056
  } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
3045
- let items = p.filteredItems ?? p.items;
3057
+ const items = p.filteredItems ?? p.items;
3046
3058
  let itemIndex = items.indexOf(item);
3047
3059
  let groupIndex = -1;
3048
3060
 
@@ -3068,7 +3080,7 @@ class DropList {
3068
3080
  if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1))
3069
3081
  return this;
3070
3082
 
3071
- let items = p.filteredItems ?? p.items;
3083
+ const items = p.filteredItems ?? p.items;
3072
3084
  let groupItem = items[groupIndex];
3073
3085
 
3074
3086
  if (!groupItem || !groupItem._group) return this;
@@ -3194,7 +3206,7 @@ class DropList {
3194
3206
  _determineVirtualMode(targetItemCount) {
3195
3207
  const p = this._p;
3196
3208
 
3197
- let items = p.filteredItems ?? p.items;
3209
+ const items = p.filteredItems ?? p.items;
3198
3210
  if (targetItemCount === undefined) {
3199
3211
  targetItemCount = items.length;
3200
3212
  }
@@ -3642,8 +3654,7 @@ class SelectBox {
3642
3654
  p.resizeObserver.observe(p.el);
3643
3655
  }
3644
3656
 
3645
- if (o.filterFn)
3646
- this.setFilterFn(o.filterFn);
3657
+ this.setFilterFn(o.filterFn);
3647
3658
 
3648
3659
  this.setItems(o.items);
3649
3660
  delete o.items; // we do not need this in memory anymore
@@ -4436,6 +4447,10 @@ class SelectBox {
4436
4447
  const p = this._p;
4437
4448
  if (p.filterFn === fn)
4438
4449
  return this;
4450
+
4451
+ // Do not keep this reference, as far as the user is concerned - he/she did not set a custom filter.
4452
+ p.filterFn = fn;
4453
+
4439
4454
  if (!fn) {
4440
4455
  // Add search by multi-item label
4441
4456
  fn = (items, term) => {
@@ -4449,7 +4464,6 @@ class SelectBox {
4449
4464
  });
4450
4465
  };
4451
4466
  }
4452
- p.filterFn = fn;
4453
4467
  p.dropList?.setFilterFn(fn);
4454
4468
  return this;
4455
4469
  }
@@ -5568,6 +5582,7 @@ class SelectBox {
5568
5582
  p.splitListCheckedGroups);
5569
5583
  }
5570
5584
  dropList.setItems(items);
5585
+ dropList.invokeRefilter();
5571
5586
  p.itemsChanged = false;
5572
5587
  p.selectionChanged = true;
5573
5588
  p.resortBySelectionNeeded = false;