@danielgindi/selectbox 1.0.64 → 1.0.67

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/lib/SelectBox.js CHANGED
@@ -2511,15 +2511,18 @@ class SelectBox {
2511
2511
 
2512
2512
  /**
2513
2513
  * @param {DropList.ItemBase} item
2514
+ * @returns {boolean} true if rendered, false if not
2514
2515
  * @private
2515
2516
  */
2516
2517
  _addMultiItemElement(item) {
2517
2518
  const p = this._p;
2518
2519
  const itemEl = this._renderMultiItem(item);
2519
- if (!itemEl) return;
2520
+ if (!itemEl) return false;
2520
2521
 
2521
2522
  before(p.inputWrapper, itemEl);
2522
2523
  p.multiItemEls.push(itemEl);
2524
+
2525
+ return true;
2523
2526
  }
2524
2527
 
2525
2528
  /** @private */
@@ -2541,10 +2544,13 @@ class SelectBox {
2541
2544
 
2542
2545
  /** @private */
2543
2546
  _syncClearButton() {
2544
- const p = this._p;
2547
+ const p = this._p,
2548
+ multiItemLabelProp = p.multiItemLabelProp;
2545
2549
 
2546
2550
  // Set clear button
2547
- if (p.selectedItems.length > 0 && p.clearable && p.showSelection) {
2551
+ if (p.selectedItems.length > 0 &&
2552
+ p.selectedItems.some(x => x[multiItemLabelProp] !== false) &&
2553
+ p.clearable && p.showSelection) {
2548
2554
  if (!p.clearButtonWrapper) {
2549
2555
  p.clearButtonWrapper = createElement(
2550
2556
  p.multi ? 'li' : 'span',
@@ -2574,7 +2580,8 @@ class SelectBox {
2574
2580
 
2575
2581
  /** @private */
2576
2582
  _syncPlaceholder() {
2577
- const p = this._p;
2583
+ const p = this._p,
2584
+ multiItemLabelProp = p.multiItemLabelProp;
2578
2585
 
2579
2586
  let placeholder = '';
2580
2587
 
@@ -2584,7 +2591,9 @@ class SelectBox {
2584
2591
  } else {
2585
2592
  placeholder = defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
2586
2593
  }
2587
- } else if (p.selectedItems.length === 0 || !p.showSelection) {
2594
+ } else if (p.selectedItems.length === 0 ||
2595
+ !p.showSelection ||
2596
+ p.selectedItems.every(x => x[multiItemLabelProp] === false)) {
2588
2597
  placeholder = p.placeholder == null ? '' : (p.placeholder + '');
2589
2598
  }
2590
2599
 
@@ -2613,13 +2622,16 @@ class SelectBox {
2613
2622
  * @returns {SelectBox}
2614
2623
  */
2615
2624
  _syncFull(fullItemsRender) {
2616
- const p = this._p;
2625
+ const p = this._p,
2626
+ multiItemLabelProp = p.multiItemLabelProp;
2617
2627
 
2618
2628
  this._renderBase();
2619
2629
  this._syncClearButton();
2620
2630
  this._syncPlaceholder();
2621
2631
 
2622
- fullItemsRender = p.multi && p.showSelection && (fullItemsRender || p.selectedItems.length !== p.multiItemEls.length);
2632
+ fullItemsRender = p.multi &&
2633
+ p.showSelection &&
2634
+ (fullItemsRender || p.selectedItems.filter(x => x[multiItemLabelProp] !== false).length !== p.multiItemEls.length);
2623
2635
 
2624
2636
  if (fullItemsRender || !p.showSelection || !p.multi) {
2625
2637
  // Remove all item elements
@@ -2672,8 +2684,9 @@ class SelectBox {
2672
2684
  break;
2673
2685
  }
2674
2686
 
2675
- actualItemCount++;
2676
- this._addMultiItemElement(items[i]);
2687
+ if (this._addMultiItemElement(items[i])) {
2688
+ actualItemCount++;
2689
+ }
2677
2690
  }
2678
2691
 
2679
2692
  if (addRestItem) {
@@ -3202,6 +3215,11 @@ class SelectBox {
3202
3215
  stickyGroup = groups[0].filter(x => stickyValues.has(x[valueProp]));
3203
3216
  if (stickyGroup.length > 0) {
3204
3217
  groups[0] = groups[0].filter(x => !stickyValues.has(x[valueProp]));
3218
+
3219
+ if (groups[0].length === 0)
3220
+ groups.shift();
3221
+ } else {
3222
+ stickyGroup = null;
3205
3223
  }
3206
3224
  }
3207
3225
 
@@ -3226,7 +3244,7 @@ class SelectBox {
3226
3244
  });
3227
3245
  }
3228
3246
 
3229
- if (stickyGroup && stickyGroup.length > 0) {
3247
+ if (stickyGroup) {
3230
3248
  groups.unshift(stickyGroup);
3231
3249
  }
3232
3250
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.64",
3
+ "version": "1.0.67",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",
package/vue/SelectBox.vue CHANGED
@@ -213,6 +213,10 @@
213
213
  type: Boolean,
214
214
  default: false,
215
215
  },
216
+ treatGroupSelectionAsItems: {
217
+ type: Boolean,
218
+ default: false,
219
+ },
216
220
  autoCheckGroupChildren: {
217
221
  type: Boolean,
218
222
  default: true,
@@ -589,6 +593,11 @@
589
593
  if (this._box)
590
594
  this._box.setIsLoadingMode(!!this.isLoadingMode);
591
595
  },
596
+
597
+ treatGroupSelectionAsItems() {
598
+ if (this._box)
599
+ this._box.setTreatGroupSelectionAsItems(!!this.treatGroupSelectionAsItems);
600
+ },
592
601
  },
593
602
 
594
603
  mounted() {
@@ -706,6 +715,7 @@
706
715
  on: this._handleBoxEvents.bind(this),
707
716
  additionalClasses: this.additionalClassesList,
708
717
  isLoadingMode: this.isLoadingMode,
718
+ treatGroupSelectionAsItems: this.treatGroupSelectionAsItems,
709
719
  });
710
720
 
711
721
  box.setValue(this.value === null ? undefined : this.value);