@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.umd.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
  (function (global, factory) {
@@ -678,7 +678,8 @@
678
678
  const p = this._p;
679
679
 
680
680
  if (this.hasFocusedItem() && p.multi) {
681
- let item = p.items[p.focusItemIndex];
681
+ const items = p.filteredItems ?? p.items;
682
+ let item = items[p.focusItemIndex];
682
683
  if (item._nocheck || item._nointeraction) return this;
683
684
 
684
685
  item._checked = !item._checked;
@@ -746,7 +747,7 @@
746
747
  const p = this._p,labelProp = p.labelProp,valueProp = p.valueProp;
747
748
 
748
749
  let isMulti = p.multi;
749
- let items = p.items;
750
+ const items = p.items;
750
751
 
751
752
  if (atIndex == null || atIndex < 0 || atIndex >= p.items.length) {
752
753
  atIndex = -1;
@@ -1211,11 +1212,10 @@
1211
1212
  if (!Array.isArray(filteredItems)) {
1212
1213
  if (term) {
1213
1214
  const matcher = new RegExp(escapeRegex(term), 'i');
1214
- const labelProp = p.labelProp;
1215
1215
 
1216
1216
  filteredItems = p.items.filter((x) => {
1217
1217
  if (!filterGroups && x._group) return true;
1218
- return matcher.test(x[labelProp]);
1218
+ return matcher.test(x.label);
1219
1219
  });
1220
1220
  } else {
1221
1221
  filteredItems = null;
@@ -1256,7 +1256,7 @@
1256
1256
  p.filteredItems = null;
1257
1257
  }
1258
1258
 
1259
- this.needsRefilter = false;
1259
+ p.needsRefilter = false;
1260
1260
 
1261
1261
  const items = p.filteredItems ?? p.items;
1262
1262
  p.hasNoResultsItem = items.length === 0 && !!p.noResultsText;
@@ -1277,11 +1277,17 @@
1277
1277
  return this;
1278
1278
  }
1279
1279
 
1280
- getFilteredItemCount() {
1280
+ rushRefilter() {
1281
1281
  const p = this._p;
1282
-
1283
1282
  if (p.needsRefilter)
1284
1283
  this._refilterItems();
1284
+ return this;
1285
+ }
1286
+
1287
+ getFilteredItemCount() {
1288
+ const p = this._p;
1289
+
1290
+ this.rushRefilter();
1285
1291
 
1286
1292
  if (p.filteredItems)
1287
1293
  return p.filteredItems.length;
@@ -1483,6 +1489,8 @@
1483
1489
 
1484
1490
  // Calculate virtual viewport size
1485
1491
  if (p.virtualListHelper.isVirtual()) {
1492
+ // Avoid extremely high size which will cause laying out the whole list
1493
+ menuEl.style.height = Math.min(el.clientHeight, document.body.clientHeight) + 'px';
1486
1494
  p.virtualListHelper.render();
1487
1495
  }
1488
1496
 
@@ -1727,6 +1735,8 @@
1727
1735
  setCheckedValues(values) {
1728
1736
  const p = this._p;
1729
1737
 
1738
+ this.rushRefilter();
1739
+
1730
1740
  let groupIndexes = [];
1731
1741
 
1732
1742
  for (let i = 0, count = p.items.length; i < count; i++) {
@@ -1790,7 +1800,7 @@
1790
1800
 
1791
1801
  excludeGroups = excludeGroups && p.groupCount > 0;
1792
1802
 
1793
- let items = [];
1803
+ const items = [];
1794
1804
 
1795
1805
  for (let i = 0, count = p.items.length; i < count; i++) {
1796
1806
  let item = p.items[i];
@@ -1831,9 +1841,7 @@
1831
1841
  }
1832
1842
  });
1833
1843
 
1834
- if (p.needsRefilter) {
1835
- this._refilterItems();
1836
- }
1844
+ this.rushRefilter();
1837
1845
 
1838
1846
  const el = p.el;
1839
1847
  el.style.position = 'absolute';
@@ -2041,6 +2049,8 @@
2041
2049
  setFocusedItemAtIndex(itemIndex) {
2042
2050
  const p = this._p;
2043
2051
 
2052
+ this.rushRefilter();
2053
+
2044
2054
  if (p.filteredItems) {
2045
2055
  const item = p.items[itemIndex];
2046
2056
  itemIndex = p.items.indexOf(item);
@@ -2238,6 +2248,8 @@
2238
2248
  setSingleSelectedItemAtIndex(itemIndex) {
2239
2249
  const p = this._p;
2240
2250
 
2251
+ this.rushRefilter();
2252
+
2241
2253
  let itemEl = null;
2242
2254
 
2243
2255
  if (itemIndex > -1 && !p.items[itemIndex]._nointeraction) {
@@ -2997,7 +3009,7 @@
2997
3009
  let affectedItems = 0;
2998
3010
 
2999
3011
  if (p.autoCheckGroupChildren) {
3000
- let items = p.filteredItems ?? p.items;
3012
+ const items = p.filteredItems ?? p.items;
3001
3013
  let groupIndex = items.indexOf(item);
3002
3014
 
3003
3015
  for (let i = groupIndex + 1, len = items.length; i < len; i++) {
@@ -3040,7 +3052,7 @@
3040
3052
  affectedItems: affectedItems
3041
3053
  });
3042
3054
  } else if (p.groupCount > 0 && p.autoCheckGroupChildren) {
3043
- let items = p.filteredItems ?? p.items;
3055
+ const items = p.filteredItems ?? p.items;
3044
3056
  let itemIndex = items.indexOf(item);
3045
3057
  let groupIndex = -1;
3046
3058
 
@@ -3066,7 +3078,7 @@
3066
3078
  if (!(p.multi && p.autoCheckGroupChildren && groupIndex > -1))
3067
3079
  return this;
3068
3080
 
3069
- let items = p.filteredItems ?? p.items;
3081
+ const items = p.filteredItems ?? p.items;
3070
3082
  let groupItem = items[groupIndex];
3071
3083
 
3072
3084
  if (!groupItem || !groupItem._group) return this;
@@ -3192,7 +3204,7 @@
3192
3204
  _determineVirtualMode(targetItemCount) {
3193
3205
  const p = this._p;
3194
3206
 
3195
- let items = p.filteredItems ?? p.items;
3207
+ const items = p.filteredItems ?? p.items;
3196
3208
  if (targetItemCount === undefined) {
3197
3209
  targetItemCount = items.length;
3198
3210
  }
@@ -3640,7 +3652,6 @@
3640
3652
  p.resizeObserver.observe(p.el);
3641
3653
  }
3642
3654
 
3643
- if (o.filterFn)
3644
3655
  this.setFilterFn(o.filterFn);
3645
3656
 
3646
3657
  this.setItems(o.items);
@@ -4434,6 +4445,10 @@
4434
4445
  const p = this._p;
4435
4446
  if (p.filterFn === fn)
4436
4447
  return this;
4448
+
4449
+ // Do not keep this reference, as far as the user is concerned - he/she did not set a custom filter.
4450
+ p.filterFn = fn;
4451
+
4437
4452
  if (!fn) {
4438
4453
  // Add search by multi-item label
4439
4454
  fn = (items, term) => {
@@ -4447,7 +4462,6 @@
4447
4462
  });
4448
4463
  };
4449
4464
  }
4450
- p.filterFn = fn;
4451
4465
  p.dropList?.setFilterFn(fn);
4452
4466
  return this;
4453
4467
  }
@@ -5566,6 +5580,7 @@
5566
5580
  p.splitListCheckedGroups);
5567
5581
  }
5568
5582
  dropList.setItems(items);
5583
+ dropList.invokeRefilter();
5569
5584
  p.itemsChanged = false;
5570
5585
  p.selectionChanged = true;
5571
5586
  p.resortBySelectionNeeded = false;