@vaadin/multi-select-combo-box 25.2.14 → 25.2.15

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.2.14",
3
+ "version": "25.2.15",
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.2.14",
41
- "@vaadin/combo-box": "~25.2.14",
42
- "@vaadin/component-base": "~25.2.14",
43
- "@vaadin/field-base": "~25.2.14",
44
- "@vaadin/input-container": "~25.2.14",
45
- "@vaadin/item": "~25.2.14",
46
- "@vaadin/lit-renderer": "~25.2.14",
47
- "@vaadin/overlay": "~25.2.14",
48
- "@vaadin/vaadin-themable-mixin": "~25.2.14",
40
+ "@vaadin/a11y-base": "~25.2.15",
41
+ "@vaadin/combo-box": "~25.2.15",
42
+ "@vaadin/component-base": "~25.2.15",
43
+ "@vaadin/field-base": "~25.2.15",
44
+ "@vaadin/input-container": "~25.2.15",
45
+ "@vaadin/item": "~25.2.15",
46
+ "@vaadin/lit-renderer": "~25.2.15",
47
+ "@vaadin/overlay": "~25.2.15",
48
+ "@vaadin/vaadin-themable-mixin": "~25.2.15",
49
49
  "lit": "^3.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@vaadin/aura": "~25.2.14",
53
- "@vaadin/chai-plugins": "~25.2.14",
54
- "@vaadin/test-runner-commands": "~25.2.14",
52
+ "@vaadin/aura": "~25.2.15",
53
+ "@vaadin/chai-plugins": "~25.2.15",
54
+ "@vaadin/test-runner-commands": "~25.2.15",
55
55
  "@vaadin/testing-helpers": "^2.0.0",
56
- "@vaadin/vaadin-lumo-styles": "~25.2.14",
56
+ "@vaadin/vaadin-lumo-styles": "~25.2.15",
57
57
  "sinon": "^22.0.0"
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": "7f2566cacb4ca4f83c44fbcc79776b4a3aa0823e"
64
+ "gitHead": "e0f3c1f28d7393af441fe3c9a790dba3e6ce3912"
65
65
  }
@@ -28,13 +28,13 @@ export const multiSelectComboBoxStyles = [
28
28
  flex: 1 0 var(--_input-min-width);
29
29
  }
30
30
 
31
- ::slotted([slot='chip']),
32
- ::slotted([slot='overflow']) {
31
+ ::slotted([slot='chip']) {
33
32
  flex: 0 1 auto;
33
+ overflow: hidden;
34
34
  }
35
35
 
36
- ::slotted([slot='chip']) {
37
- overflow: hidden;
36
+ ::slotted([slot='overflow']) {
37
+ flex: none;
38
38
  }
39
39
 
40
40
  :host(:is([readonly], [disabled])) ::slotted(input) {
@@ -52,6 +52,10 @@ export const multiSelectComboBoxChipStyles = css`
52
52
  translate: 25%;
53
53
  }
54
54
 
55
+ :host(:dir(rtl)) [part='remove-button'] {
56
+ translate: -25%;
57
+ }
58
+
55
59
  [part='remove-button']::before {
56
60
  content: '';
57
61
  display: block;
@@ -62,11 +66,8 @@ export const multiSelectComboBoxChipStyles = css`
62
66
  }
63
67
 
64
68
  :host([disabled]) {
65
- cursor: var(--vaadin-disabled-cursor);
66
- }
67
-
68
- :host([disabled]) [part='label'] {
69
69
  --vaadin-chip-text-color: var(--vaadin-text-color-disabled);
70
+ cursor: var(--vaadin-disabled-cursor);
70
71
  }
71
72
 
72
73
  :host([hidden]),
@@ -90,11 +91,11 @@ export const multiSelectComboBoxChipStyles = css`
90
91
  }
91
92
 
92
93
  :host([slot='overflow'])::before {
93
- left: calc(-4px - var(--vaadin-chip-border-width, 1px));
94
+ inset-inline-start: calc(-4px - var(--vaadin-chip-border-width, 1px));
94
95
  }
95
96
 
96
97
  :host([slot='overflow'])::after {
97
- left: calc(-8px - var(--vaadin-chip-border-width, 1px));
98
+ inset-inline-start: calc(-8px - var(--vaadin-chip-border-width, 1px));
98
99
  }
99
100
 
100
101
  :host([count='2']) {
@@ -926,27 +926,49 @@ export const MultiSelectComboBoxMixin = (superClass) =>
926
926
  return chip;
927
927
  }
928
928
 
929
+ /**
930
+ * Returns the width of the element with its fraction, unlike `clientWidth`.
931
+ * The chips do not shrink below their `max-width`, so a rounding error moves the input out.
932
+ * @private
933
+ */
934
+ __getUsedWidth(element) {
935
+ return parseFloat(getComputedStyle(element).width);
936
+ }
937
+
929
938
  /** @private */
930
- __getWrapperWidth() {
931
- return this._inputField.$.wrapper.clientWidth;
939
+ __getWrapperGap() {
940
+ // The gap computes to `normal` when not set, which is 0 in a flex container
941
+ return parseFloat(getComputedStyle(this._inputField.$.wrapper).columnGap) || 0;
932
942
  }
933
943
 
934
944
  /** @private */
935
- __getOverflowWidth() {
945
+ __getWrapperWidth() {
946
+ // Exclude the gap between the chips and the input
947
+ return this.__getUsedWidth(this._inputField.$.wrapper) - this.__getWrapperGap();
948
+ }
949
+
950
+ /**
951
+ * Returns the width that the overflow chip with the given count takes,
952
+ * including its margins and the gap between it and the chips.
953
+ * @private
954
+ */
955
+ __getOverflowWidth(count) {
936
956
  const chip = this._overflow;
937
957
 
958
+ // The `_overflowItems` observer sets the final label and count afterwards
938
959
  chip.style.visibility = 'hidden';
939
960
  chip.removeAttribute('hidden');
961
+ chip.label = `${count}`;
962
+ chip.setAttribute('count', `${count}`);
940
963
 
941
- const count = chip.getAttribute('count');
964
+ // The chip uses `box-sizing: border-box`, so its width includes padding and border
965
+ const { marginInlineStart, marginInlineEnd } = getComputedStyle(chip);
966
+ const overflowWidth =
967
+ this.__getUsedWidth(chip) +
968
+ parseFloat(marginInlineStart) +
969
+ parseFloat(marginInlineEnd) +
970
+ this.__getWrapperGap();
942
971
 
943
- // Detect max possible width of the overflow chip
944
- // by measuring it with widest number (2 digits)
945
- chip.setAttribute('count', '99');
946
- const overflowStyle = getComputedStyle(chip);
947
- const overflowWidth = chip.clientWidth + parseInt(overflowStyle.marginInlineStart);
948
-
949
- chip.setAttribute('count', count);
950
972
  chip.setAttribute('hidden', '');
951
973
  chip.style.visibility = '';
952
974
 
@@ -978,7 +1000,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
978
1000
  return;
979
1001
  }
980
1002
 
981
- const inputWidth = parseInt(getComputedStyle(this.inputElement).flexBasis);
1003
+ const inputWidth = parseFloat(getComputedStyle(this.inputElement).flexBasis);
982
1004
 
983
1005
  if (this.collapseChips) {
984
1006
  this._overflowItems = this.__updateChipsCollapsed(this.selectedItems, inputWidth);
@@ -997,7 +1019,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
997
1019
  return chip;
998
1020
  });
999
1021
 
1000
- const allChipsFit = this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth;
1022
+ const allChipsFit = this.__getWrapperWidth() - this.__getUsedWidth(this.$.chips) >= inputWidth;
1001
1023
  return { chips, allChipsFit };
1002
1024
  }
1003
1025
 
@@ -1024,21 +1046,28 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1024
1046
 
1025
1047
  // Remove chips from the end until there is enough width for the input element to fit,
1026
1048
  // keeping at least one chip visible
1027
- const overflowWidth = this.__getOverflowWidth();
1049
+ const wrapperWidth = this.__getWrapperWidth();
1050
+ // Start from the width for the largest count, and measure the exact count only
1051
+ // when the chips would fit with the estimate, as the label width varies per count
1052
+ let overflowWidth = this.__getOverflowWidth(items.length - 1);
1028
1053
  let visibleCount = chips.length;
1029
1054
 
1030
1055
  while (visibleCount > 1) {
1031
1056
  visibleCount -= 1;
1032
1057
  chips[visibleCount].remove();
1033
1058
 
1034
- if (this.__getWrapperWidth() - this.$.chips.clientWidth >= inputWidth + overflowWidth) {
1035
- break;
1059
+ const chipsWidth = this.__getUsedWidth(this.$.chips);
1060
+ if (wrapperWidth - chipsWidth >= inputWidth + overflowWidth) {
1061
+ overflowWidth = this.__getOverflowWidth(items.length - visibleCount);
1062
+ if (wrapperWidth - chipsWidth >= inputWidth + overflowWidth) {
1063
+ break;
1064
+ }
1036
1065
  }
1037
1066
  }
1038
1067
 
1039
1068
  if (visibleCount === 1) {
1040
1069
  const chipMinWidth = parseInt(getComputedStyle(this).getPropertyValue('--_chip-min-width'));
1041
- const remainingWidth = this.__getWrapperWidth() - inputWidth - overflowWidth;
1070
+ const remainingWidth = wrapperWidth - inputWidth - overflowWidth;
1042
1071
  chips[0].style.maxWidth = `${Math.max(chipMinWidth, remainingWidth)}px`;
1043
1072
  }
1044
1073
 
@@ -1047,11 +1076,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1047
1076
 
1048
1077
  /** @private */
1049
1078
  __updateChipsDefault(items, inputWidth) {
1050
- let remainingWidth = this.__getWrapperWidth() - inputWidth;
1051
-
1052
- if (items.length > 1) {
1053
- remainingWidth -= this.__getOverflowWidth();
1054
- }
1079
+ const availableWidth = this.__getWrapperWidth() - inputWidth;
1055
1080
 
1056
1081
  const chipMinWidth = parseInt(getComputedStyle(this).getPropertyValue('--_chip-min-width'));
1057
1082
 
@@ -1060,7 +1085,12 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1060
1085
  const chip = this.__createChip(items[i]);
1061
1086
  this.insertBefore(chip, refNode);
1062
1087
 
1063
- if (this.$.chips.clientWidth > remainingWidth) {
1088
+ // Reserve space for the overflow chip with the count of the items that are not
1089
+ // added yet, measured with a chip rendered so that the spacing between them counts
1090
+ const remainingWidth =
1091
+ items.length > 1 ? availableWidth - this.__getOverflowWidth(Math.max(i, 1)) : availableWidth;
1092
+
1093
+ if (this.__getUsedWidth(this.$.chips) > remainingWidth) {
1064
1094
  // If there is no more space for chips, or if there is at least one
1065
1095
  // chip already shown, collapse all remaining chips to the overflow
1066
1096
  if (remainingWidth < chipMinWidth || refNode !== null) {
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/multi-select-combo-box",
4
- "version": "25.2.14",
4
+ "version": "25.2.15",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/multi-select-combo-box",
4
- "version": "25.2.14",
4
+ "version": "25.2.15",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {