@vaadin/multi-select-combo-box 25.2.0-alpha9 → 25.2.0-beta2

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.
@@ -78,6 +78,14 @@ export declare class MultiSelectComboBoxMixinClass<TItem> {
78
78
  */
79
79
  autoExpandVertically: boolean;
80
80
 
81
+ /**
82
+ * Set to true to collapse all selected items chips into the overflow
83
+ * chip when they don't all fit, instead of showing as many as possible.
84
+ * Has no effect when `autoExpandVertically` is true.
85
+ * @attr {boolean} collapse-chips
86
+ */
87
+ collapseChips: boolean;
88
+
81
89
  /**
82
90
  * When true, the user can input a value that is not present in the items list.
83
91
  * @attr {boolean} allow-custom-value
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { announce } from '@vaadin/a11y-base/src/announce.js';
7
7
  import { ComboBoxDataProviderMixin } from '@vaadin/combo-box/src/vaadin-combo-box-data-provider-mixin.js';
8
+ import { ComboBoxFocusIndexMixin } from '@vaadin/combo-box/src/vaadin-combo-box-focus-index-mixin.js';
8
9
  import { ComboBoxItemsMixin } from '@vaadin/combo-box/src/vaadin-combo-box-items-mixin.js';
9
10
  import { ComboBoxPlaceholder } from '@vaadin/combo-box/src/vaadin-combo-box-placeholder.js';
10
11
  import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
@@ -23,18 +24,9 @@ const DEFAULT_I18N = {
23
24
  total: '{count} items selected',
24
25
  };
25
26
 
26
- /**
27
- * @polymerMixin
28
- * @mixes ComboBoxDataProviderMixin
29
- * @mixes ComboBoxItemsMixin
30
- * @mixes I18nMixin
31
- * @mixes InputControlMixin
32
- * @mixes ResizeMixin
33
- */
34
27
  export const MultiSelectComboBoxMixin = (superClass) =>
35
28
  class MultiSelectComboBoxMixinClass extends I18nMixin(
36
- DEFAULT_I18N,
37
- ComboBoxDataProviderMixin(ComboBoxItemsMixin(InputControlMixin(ResizeMixin(superClass)))),
29
+ ComboBoxFocusIndexMixin(ComboBoxDataProviderMixin(ComboBoxItemsMixin(InputControlMixin(ResizeMixin(superClass))))),
38
30
  ) {
39
31
  static get properties() {
40
32
  return {
@@ -63,6 +55,19 @@ export const MultiSelectComboBoxMixin = (superClass) =>
63
55
  sync: true,
64
56
  },
65
57
 
58
+ /**
59
+ * Set to true to collapse all selected items chips into the overflow
60
+ * chip when they don't all fit, instead of showing as many as possible.
61
+ * Has no effect when `autoExpandVertically` is true.
62
+ * @attr {boolean} collapse-chips
63
+ */
64
+ collapseChips: {
65
+ type: Boolean,
66
+ value: false,
67
+ reflectToAttribute: true,
68
+ sync: true,
69
+ },
70
+
66
71
  /**
67
72
  * A function used to generate CSS class names for dropdown
68
73
  * items and selected chips based on the item. The return
@@ -218,6 +223,10 @@ export const MultiSelectComboBoxMixin = (superClass) =>
218
223
  ];
219
224
  }
220
225
 
226
+ static get defaultI18n() {
227
+ return DEFAULT_I18N;
228
+ }
229
+
221
230
  /**
222
231
  * The object used to localize this component. To change the default
223
232
  * localization, replace this with an object that provides all properties, or
@@ -346,6 +355,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
346
355
  const chipProps = [
347
356
  'autoExpandHorizontally',
348
357
  'autoExpandVertically',
358
+ 'collapseChips',
349
359
  'disabled',
350
360
  'readonly',
351
361
  'clearButtonVisible',
@@ -483,7 +493,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
483
493
  __openedOrItemsChanged(opened, items, loading, keepOverlayOpened) {
484
494
  // Close the overlay if there are no items to display.
485
495
  // See https://github.com/vaadin/vaadin-combo-box/pull/964
486
- this._overlayOpened = opened && (keepOverlayOpened || loading || !!(items && items.length));
496
+ this._overlayOpened = opened && (keepOverlayOpened || loading || !!items?.length);
487
497
  }
488
498
 
489
499
  /**
@@ -696,7 +706,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
696
706
  return;
697
707
  }
698
708
 
699
- if (items && items.length && this._topGroup && this._topGroup.length) {
709
+ if (items?.length && this._topGroup?.length) {
700
710
  // Filter out items included to the top group.
701
711
  const filteredItems = items.filter((item) => this._findIndex(item, this._topGroup, this.itemIdPath) === -1);
702
712
 
@@ -717,6 +727,18 @@ export const MultiSelectComboBoxMixin = (superClass) =>
717
727
  // when the user types in a filter query.
718
728
  const focusedItem = oldItems ? oldItems[this._focusedIndex] : null;
719
729
 
730
+ // When both the previously-focused entry and the new entry at the
731
+ // same index are placeholders (e.g. the Flow connector mid-scroll
732
+ // re-pushing `__setDropdownItems`), preserve `_focusedIndex` until
733
+ // a follow-up call lands a real item at that position.
734
+ if (
735
+ oldItems &&
736
+ oldItems[this._focusedIndex] instanceof ComboBoxPlaceholder &&
737
+ newItems[this._focusedIndex] instanceof ComboBoxPlaceholder
738
+ ) {
739
+ return;
740
+ }
741
+
720
742
  // Try to first set focus on the item that had been focused before `newItems` were updated
721
743
  // if it is still present in the `newItems` array. Otherwise, set the focused index
722
744
  // depending on the selected item or the filter query.
@@ -797,7 +819,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
797
819
  if (index !== -1) {
798
820
  const lastFilter = this._lastFilter;
799
821
  // Do not unselect when manually typing and committing an already selected item.
800
- if (lastFilter && lastFilter.toLowerCase() === itemLabel.toLowerCase()) {
822
+ if (lastFilter?.toLowerCase() === itemLabel.toLowerCase()) {
801
823
  this.__clearInternalValue();
802
824
  return;
803
825
  }
@@ -926,7 +948,9 @@ export const MultiSelectComboBoxMixin = (superClass) =>
926
948
 
927
949
  const inputWidth = parseInt(getComputedStyle(this.inputElement).flexBasis);
928
950
 
929
- if (this.autoExpandHorizontally) {
951
+ if (this.collapseChips) {
952
+ this._overflowItems = this.__updateChipsCollapsed(this.selectedItems, inputWidth);
953
+ } else if (this.autoExpandHorizontally) {
930
954
  this._overflowItems = this.__updateChipsHorizontalExpand(this.selectedItems, inputWidth);
931
955
  } else {
932
956
  this._overflowItems = this.__updateChipsDefault(this.selectedItems, inputWidth);
@@ -934,15 +958,35 @@ export const MultiSelectComboBoxMixin = (superClass) =>
934
958
  }
935
959
 
936
960
  /** @private */
937
- __updateChipsHorizontalExpand(items, inputWidth) {
938
- // Add all chips to make the field fully expand
961
+ __renderAllChips(items, inputWidth) {
939
962
  const chips = items.map((item) => {
940
963
  const chip = this.__createChip(item);
941
964
  this.appendChild(chip);
942
965
  return chip;
943
966
  });
944
967
 
945
- if (this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth) {
968
+ const allChipsFit = this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth;
969
+ return { chips, allChipsFit };
970
+ }
971
+
972
+ /** @private */
973
+ __updateChipsCollapsed(items, inputWidth) {
974
+ const { chips, allChipsFit } = this.__renderAllChips(items, inputWidth);
975
+
976
+ if (allChipsFit) {
977
+ return [];
978
+ }
979
+
980
+ // Not enough space: remove all chips, collapse everything to overflow
981
+ chips.forEach((chip) => chip.remove());
982
+ return items.slice();
983
+ }
984
+
985
+ /** @private */
986
+ __updateChipsHorizontalExpand(items, inputWidth) {
987
+ const { chips, allChipsFit } = this.__renderAllChips(items, inputWidth);
988
+
989
+ if (allChipsFit) {
946
990
  return [];
947
991
  }
948
992
 
@@ -1298,10 +1342,4 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1298
1342
  // and keep the overlay opened when clicking a chip.
1299
1343
  event.preventDefault();
1300
1344
  }
1301
-
1302
- /**
1303
- * Fired when the user sets a custom value.
1304
- * @event custom-value-set
1305
- * @param {string} detail the custom value
1306
- */
1307
1345
  };
@@ -19,10 +19,6 @@ import { multiSelectComboBoxOverlayStyles } from './styles/vaadin-multi-select-c
19
19
  *
20
20
  * @customElement vaadin-multi-select-combo-box-overlay
21
21
  * @extends HTMLElement
22
- * @mixes ComboBoxOverlayMixin
23
- * @mixes DirMixin
24
- * @mixes OverlayMixin
25
- * @mixes ThemableMixin
26
22
  * @private
27
23
  */
28
24
  class MultiSelectComboBoxOverlay extends ComboBoxOverlayMixin(
@@ -15,7 +15,6 @@ import { multiSelectComboBoxScrollerStyles } from './styles/vaadin-multi-select-
15
15
  *
16
16
  * @customElement vaadin-multi-select-combo-box-scroller
17
17
  * @extends HTMLElement
18
- * @mixes ComboBoxScrollerMixin
19
18
  * @private
20
19
  */
21
20
  export class MultiSelectComboBoxScroller extends ComboBoxScrollerMixin(PolylitMixin(LitElement)) {
@@ -98,9 +98,6 @@ import { MultiSelectComboBoxMixin } from './vaadin-multi-select-combo-box-mixin.
98
98
  *
99
99
  * @customElement vaadin-multi-select-combo-box
100
100
  * @extends HTMLElement
101
- * @mixes ElementMixin
102
- * @mixes ThemableMixin
103
- * @mixes MultiSelectComboBoxMixin
104
101
  */
105
102
  class MultiSelectComboBox extends MultiSelectComboBoxMixin(
106
103
  ThemableMixin(ElementMixin(PolylitMixin(LumoInjectionMixin(LitElement)))),