@vaadin/combo-box 22.0.10 → 22.0.11

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/combo-box",
3
- "version": "22.0.10",
3
+ "version": "22.0.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,23 +33,23 @@
33
33
  "dependencies": {
34
34
  "@open-wc/dedupe-mixin": "^1.3.0",
35
35
  "@polymer/polymer": "^3.0.0",
36
- "@vaadin/component-base": "^22.0.10",
37
- "@vaadin/field-base": "^22.0.10",
38
- "@vaadin/input-container": "^22.0.10",
39
- "@vaadin/item": "^22.0.10",
40
- "@vaadin/vaadin-lumo-styles": "^22.0.10",
41
- "@vaadin/vaadin-material-styles": "^22.0.10",
42
- "@vaadin/vaadin-overlay": "^22.0.10",
43
- "@vaadin/vaadin-themable-mixin": "^22.0.10"
36
+ "@vaadin/component-base": "^22.0.11",
37
+ "@vaadin/field-base": "^22.0.11",
38
+ "@vaadin/input-container": "^22.0.11",
39
+ "@vaadin/item": "^22.0.11",
40
+ "@vaadin/vaadin-lumo-styles": "^22.0.11",
41
+ "@vaadin/vaadin-material-styles": "^22.0.11",
42
+ "@vaadin/vaadin-overlay": "^22.0.11",
43
+ "@vaadin/vaadin-themable-mixin": "^22.0.11"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@esm-bundle/chai": "^4.3.4",
47
- "@vaadin/dialog": "^22.0.10",
48
- "@vaadin/polymer-legacy-adapter": "^22.0.10",
47
+ "@vaadin/dialog": "^22.0.11",
48
+ "@vaadin/polymer-legacy-adapter": "^22.0.11",
49
49
  "@vaadin/testing-helpers": "^0.3.2",
50
- "@vaadin/text-field": "^22.0.10",
50
+ "@vaadin/text-field": "^22.0.11",
51
51
  "lit": "^2.0.0",
52
52
  "sinon": "^9.2.0"
53
53
  },
54
- "gitHead": "5977183ebfe56b017da471fd9162bb72e9ed477a"
54
+ "gitHead": "a905b1ef7af885ce5536646e818fe76574407237"
55
55
  }
@@ -564,20 +564,27 @@ export const ComboBoxMixin = (subclass) =>
564
564
 
565
565
  /** @private */
566
566
  _onEnter(e) {
567
- // should close on enter when custom values are allowed, input field is cleared, or when an existing
568
- // item is focused with keyboard. If auto open is disabled, under the same conditions, commit value.
569
- if (
570
- (this.opened || this.autoOpenDisabled) &&
571
- (this.allowCustomValue || this._inputElementValue === '' || this._focusedIndex > -1)
572
- ) {
573
- this._closeOrCommit();
574
-
567
+ // do not commit value when custom values are disallowed and input value is not a valid option
568
+ // also stop propagation of the event, otherwise the user could submit a form while the input
569
+ // still contains an invalid value
570
+ if (!this.allowCustomValue && this._inputElementValue !== '' && this._focusedIndex < 0) {
575
571
  // Do not submit the surrounding form.
576
572
  e.preventDefault();
573
+ // Do not trigger global listeners
574
+ e.stopPropagation();
575
+ return;
576
+ }
577
577
 
578
+ // stop propagation of the enter event only if the dropdown is opened, this
579
+ // "consumes" the enter event for the action of closing the dropdown
580
+ if (this.opened) {
581
+ // Do not submit the surrounding form.
582
+ e.preventDefault();
578
583
  // Do not trigger global listeners
579
584
  e.stopPropagation();
580
585
  }
586
+
587
+ this._closeOrCommit();
581
588
  }
582
589
 
583
590
  /**
@@ -950,17 +957,23 @@ export const ComboBoxMixin = (subclass) =>
950
957
  if (e.path === 'filteredItems' || e.path === 'filteredItems.splices') {
951
958
  this._setOverlayItems(this.filteredItems);
952
959
 
953
- this._focusedIndex =
954
- this.opened || this.autoOpenDisabled
955
- ? this.$.dropdown.indexOfLabel(this.filter)
956
- : this._indexOfValue(this.value, this.filteredItems);
960
+ // When the external filtering is used and `value` was provided before `filteredItems`,
961
+ // initialize the selected item with the current value here. This will also cause
962
+ // the input element value to sync. In other cases, the selected item is already initialized
963
+ // in other observers such as `valueChanged`, `_itemsOrPathsChanged`.
964
+ const valueIndex = this._indexOfValue(this.value, this.filteredItems);
965
+ if (this.selectedItem === null && valueIndex >= 0) {
966
+ this._selectItemForValue(this.value);
967
+ }
957
968
 
958
- // see https://github.com/vaadin/web-components/issues/2615
959
- if (this.selectedItem === null && this._focusedIndex >= 0) {
960
- const filteredItem = this.filteredItems[this._focusedIndex];
961
- if (this._getItemValue(filteredItem) === this.value) {
962
- this._selectItemForValue(this.value);
963
- }
969
+ if (this._inputElementValue === undefined || this._inputElementValue === this.value) {
970
+ // When the input element value is the same as the current value or not defined,
971
+ // set the focused index to the item that matches the value.
972
+ this._focusedIndex = this._indexOfValue(this.value, this.filteredItems);
973
+ } else {
974
+ // When the user filled in something that is different from the current value = filtering is enabled,
975
+ // set the focused index to the item that matches the filter query.
976
+ this._focusedIndex = this.$.dropdown.indexOfLabel(this.filter);
964
977
  }
965
978
  }
966
979
  }
@@ -985,12 +998,13 @@ export const ComboBoxMixin = (subclass) =>
985
998
  const valueIndex = this._indexOfValue(value, this.filteredItems);
986
999
  const previouslySelectedItem = this.selectedItem;
987
1000
 
988
- this.selectedItem =
989
- valueIndex >= 0
990
- ? this.filteredItems[valueIndex]
991
- : this.dataProvider && this.selectedItem === undefined
992
- ? undefined
993
- : null;
1001
+ if (valueIndex >= 0) {
1002
+ this.selectedItem = this.filteredItems[valueIndex];
1003
+ } else if (this.dataProvider && this.selectedItem === undefined) {
1004
+ this.selectedItem = undefined;
1005
+ } else {
1006
+ this.selectedItem = null;
1007
+ }
994
1008
 
995
1009
  if (this.selectedItem === null && previouslySelectedItem === null) {
996
1010
  this._selectedItemChanged(this.selectedItem);
@@ -1014,15 +1028,17 @@ export const ComboBoxMixin = (subclass) =>
1014
1028
 
1015
1029
  /** @private */
1016
1030
  _indexOfValue(value, items) {
1017
- if (items && this._isValidValue(value)) {
1018
- for (let i = 0; i < items.length; i++) {
1019
- if (items[i] !== this.__placeHolder && this._getItemValue(items[i]) === value) {
1020
- return i;
1021
- }
1022
- }
1031
+ if (!items || !this._isValidValue(value)) {
1032
+ return -1;
1023
1033
  }
1024
1034
 
1025
- return -1;
1035
+ return items.findIndex((item) => {
1036
+ if (item instanceof ComboBoxPlaceholder) {
1037
+ return false;
1038
+ }
1039
+
1040
+ return this._getItemValue(item) === value;
1041
+ });
1026
1042
  }
1027
1043
 
1028
1044
  /**
@@ -251,9 +251,16 @@ export class ComboBoxScroller extends PolymerElement {
251
251
  }
252
252
 
253
253
  /** @private */
254
- __focusedIndexChanged(index) {
255
- if (this.__virtualizer && index >= 0) {
254
+ __focusedIndexChanged(index, oldIndex) {
255
+ if (!this.__virtualizer) {
256
+ return;
257
+ }
258
+
259
+ if (index !== oldIndex) {
256
260
  this.requestContentUpdate();
261
+ }
262
+
263
+ if (index >= 0) {
257
264
  this.scrollIntoView(index);
258
265
  }
259
266
  }