@vaadin/multi-select-combo-box 25.1.2 → 25.2.0-alpha10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/multi-select-combo-box",
3
- "version": "25.1.2",
3
+ "version": "25.2.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,23 +37,23 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@open-wc/dedupe-mixin": "^1.3.0",
40
- "@vaadin/a11y-base": "~25.1.2",
41
- "@vaadin/combo-box": "~25.1.2",
42
- "@vaadin/component-base": "~25.1.2",
43
- "@vaadin/field-base": "~25.1.2",
44
- "@vaadin/input-container": "~25.1.2",
45
- "@vaadin/item": "~25.1.2",
46
- "@vaadin/lit-renderer": "~25.1.2",
47
- "@vaadin/overlay": "~25.1.2",
48
- "@vaadin/vaadin-themable-mixin": "~25.1.2",
40
+ "@vaadin/a11y-base": "25.2.0-alpha10",
41
+ "@vaadin/combo-box": "25.2.0-alpha10",
42
+ "@vaadin/component-base": "25.2.0-alpha10",
43
+ "@vaadin/field-base": "25.2.0-alpha10",
44
+ "@vaadin/input-container": "25.2.0-alpha10",
45
+ "@vaadin/item": "25.2.0-alpha10",
46
+ "@vaadin/lit-renderer": "25.2.0-alpha10",
47
+ "@vaadin/overlay": "25.2.0-alpha10",
48
+ "@vaadin/vaadin-themable-mixin": "25.2.0-alpha10",
49
49
  "lit": "^3.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@vaadin/aura": "~25.1.2",
53
- "@vaadin/chai-plugins": "~25.1.2",
54
- "@vaadin/test-runner-commands": "~25.1.2",
52
+ "@vaadin/aura": "25.2.0-alpha10",
53
+ "@vaadin/chai-plugins": "25.2.0-alpha10",
54
+ "@vaadin/test-runner-commands": "25.2.0-alpha10",
55
55
  "@vaadin/testing-helpers": "^2.0.0",
56
- "@vaadin/vaadin-lumo-styles": "~25.1.2",
56
+ "@vaadin/vaadin-lumo-styles": "25.2.0-alpha10",
57
57
  "sinon": "^21.0.2"
58
58
  },
59
59
  "customElements": "custom-elements.json",
@@ -61,5 +61,5 @@
61
61
  "web-types.json",
62
62
  "web-types.lit.json"
63
63
  ],
64
- "gitHead": "48e5dc507ac5eb8d34839be06cac652f1635fe1c"
64
+ "gitHead": "1303b6a3eeecb44a9d26f2b53cb56d9e906febdf"
65
65
  }
@@ -12,6 +12,7 @@ import type { ComboBoxItemModel } from '@vaadin/combo-box/src/vaadin-combo-box.j
12
12
  import type { ComboBoxBaseMixinClass } from '@vaadin/combo-box/src/vaadin-combo-box-base-mixin.js';
13
13
  import type { ComboBoxDataProviderMixinClass } from '@vaadin/combo-box/src/vaadin-combo-box-data-provider-mixin.js';
14
14
  import type { ComboBoxItemsMixinClass } from '@vaadin/combo-box/src/vaadin-combo-box-items-mixin.js';
15
+ import type { ComboBoxScrollToIndexMixinClass } from '@vaadin/combo-box/src/vaadin-combo-box-scroll-to-index-mixin.js';
15
16
  import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
16
17
  import type { I18nMixinClass } from '@vaadin/component-base/src/i18n-mixin.js';
17
18
  import type { ResizeMixinClass } from '@vaadin/component-base/src/resize-mixin.js';
@@ -45,6 +46,7 @@ export declare function MultiSelectComboBoxMixin<TItem, T extends Constructor<HT
45
46
  Constructor<ComboBoxBaseMixinClass> &
46
47
  Constructor<ComboBoxDataProviderMixinClass<TItem>> &
47
48
  Constructor<ComboBoxItemsMixinClass<TItem>> &
49
+ Constructor<ComboBoxScrollToIndexMixinClass> &
48
50
  Constructor<DelegateFocusMixinClass> &
49
51
  Constructor<DelegateStateMixinClass> &
50
52
  Constructor<DisabledMixinClass> &
@@ -78,6 +80,14 @@ export declare class MultiSelectComboBoxMixinClass<TItem> {
78
80
  */
79
81
  autoExpandVertically: boolean;
80
82
 
83
+ /**
84
+ * Set to true to collapse all selected items chips into the overflow
85
+ * chip when they don't all fit, instead of showing as many as possible.
86
+ * Has no effect when `autoExpandVertically` is true.
87
+ * @attr {boolean} collapse-chips
88
+ */
89
+ collapseChips: boolean;
90
+
81
91
  /**
82
92
  * When true, the user can input a value that is not present in the items list.
83
93
  * @attr {boolean} allow-custom-value
@@ -7,6 +7,7 @@ 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
8
  import { ComboBoxItemsMixin } from '@vaadin/combo-box/src/vaadin-combo-box-items-mixin.js';
9
9
  import { ComboBoxPlaceholder } from '@vaadin/combo-box/src/vaadin-combo-box-placeholder.js';
10
+ import { ComboBoxScrollToIndexMixin } from '@vaadin/combo-box/src/vaadin-combo-box-scroll-to-index-mixin.js';
10
11
  import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
11
12
  import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js';
12
13
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -27,6 +28,7 @@ const DEFAULT_I18N = {
27
28
  * @polymerMixin
28
29
  * @mixes ComboBoxDataProviderMixin
29
30
  * @mixes ComboBoxItemsMixin
31
+ * @mixes ComboBoxScrollToIndexMixin
30
32
  * @mixes I18nMixin
31
33
  * @mixes InputControlMixin
32
34
  * @mixes ResizeMixin
@@ -34,7 +36,9 @@ const DEFAULT_I18N = {
34
36
  export const MultiSelectComboBoxMixin = (superClass) =>
35
37
  class MultiSelectComboBoxMixinClass extends I18nMixin(
36
38
  DEFAULT_I18N,
37
- ComboBoxDataProviderMixin(ComboBoxItemsMixin(InputControlMixin(ResizeMixin(superClass)))),
39
+ ComboBoxScrollToIndexMixin(
40
+ ComboBoxDataProviderMixin(ComboBoxItemsMixin(InputControlMixin(ResizeMixin(superClass)))),
41
+ ),
38
42
  ) {
39
43
  static get properties() {
40
44
  return {
@@ -63,6 +67,19 @@ export const MultiSelectComboBoxMixin = (superClass) =>
63
67
  sync: true,
64
68
  },
65
69
 
70
+ /**
71
+ * Set to true to collapse all selected items chips into the overflow
72
+ * chip when they don't all fit, instead of showing as many as possible.
73
+ * Has no effect when `autoExpandVertically` is true.
74
+ * @attr {boolean} collapse-chips
75
+ */
76
+ collapseChips: {
77
+ type: Boolean,
78
+ value: false,
79
+ reflectToAttribute: true,
80
+ sync: true,
81
+ },
82
+
66
83
  /**
67
84
  * A function used to generate CSS class names for dropdown
68
85
  * items and selected chips based on the item. The return
@@ -346,6 +363,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
346
363
  const chipProps = [
347
364
  'autoExpandHorizontally',
348
365
  'autoExpandVertically',
366
+ 'collapseChips',
349
367
  'disabled',
350
368
  'readonly',
351
369
  'clearButtonVisible',
@@ -483,7 +501,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
483
501
  __openedOrItemsChanged(opened, items, loading, keepOverlayOpened) {
484
502
  // Close the overlay if there are no items to display.
485
503
  // See https://github.com/vaadin/vaadin-combo-box/pull/964
486
- this._overlayOpened = opened && (keepOverlayOpened || loading || !!(items && items.length));
504
+ this._overlayOpened = opened && (keepOverlayOpened || loading || !!items?.length);
487
505
  }
488
506
 
489
507
  /**
@@ -696,7 +714,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
696
714
  return;
697
715
  }
698
716
 
699
- if (items && items.length && this._topGroup && this._topGroup.length) {
717
+ if (items?.length && this._topGroup?.length) {
700
718
  // Filter out items included to the top group.
701
719
  const filteredItems = items.filter((item) => this._findIndex(item, this._topGroup, this.itemIdPath) === -1);
702
720
 
@@ -797,7 +815,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
797
815
  if (index !== -1) {
798
816
  const lastFilter = this._lastFilter;
799
817
  // Do not unselect when manually typing and committing an already selected item.
800
- if (lastFilter && lastFilter.toLowerCase() === itemLabel.toLowerCase()) {
818
+ if (lastFilter?.toLowerCase() === itemLabel.toLowerCase()) {
801
819
  this.__clearInternalValue();
802
820
  return;
803
821
  }
@@ -926,7 +944,9 @@ export const MultiSelectComboBoxMixin = (superClass) =>
926
944
 
927
945
  const inputWidth = parseInt(getComputedStyle(this.inputElement).flexBasis);
928
946
 
929
- if (this.autoExpandHorizontally) {
947
+ if (this.collapseChips) {
948
+ this._overflowItems = this.__updateChipsCollapsed(this.selectedItems, inputWidth);
949
+ } else if (this.autoExpandHorizontally) {
930
950
  this._overflowItems = this.__updateChipsHorizontalExpand(this.selectedItems, inputWidth);
931
951
  } else {
932
952
  this._overflowItems = this.__updateChipsDefault(this.selectedItems, inputWidth);
@@ -934,15 +954,35 @@ export const MultiSelectComboBoxMixin = (superClass) =>
934
954
  }
935
955
 
936
956
  /** @private */
937
- __updateChipsHorizontalExpand(items, inputWidth) {
938
- // Add all chips to make the field fully expand
957
+ __renderAllChips(items, inputWidth) {
939
958
  const chips = items.map((item) => {
940
959
  const chip = this.__createChip(item);
941
960
  this.appendChild(chip);
942
961
  return chip;
943
962
  });
944
963
 
945
- if (this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth) {
964
+ const allChipsFit = this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth;
965
+ return { chips, allChipsFit };
966
+ }
967
+
968
+ /** @private */
969
+ __updateChipsCollapsed(items, inputWidth) {
970
+ const { chips, allChipsFit } = this.__renderAllChips(items, inputWidth);
971
+
972
+ if (allChipsFit) {
973
+ return [];
974
+ }
975
+
976
+ // Not enough space: remove all chips, collapse everything to overflow
977
+ chips.forEach((chip) => chip.remove());
978
+ return items.slice();
979
+ }
980
+
981
+ /** @private */
982
+ __updateChipsHorizontalExpand(items, inputWidth) {
983
+ const { chips, allChipsFit } = this.__renderAllChips(items, inputWidth);
984
+
985
+ if (allChipsFit) {
946
986
  return [];
947
987
  }
948
988
 
@@ -1298,10 +1338,4 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1298
1338
  // and keep the overlay opened when clicking a chip.
1299
1339
  event.preventDefault();
1300
1340
  }
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
1341
  };