@vaadin/vaadin-combo-box 5.4.11 → 5.4.13

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
@@ -10,7 +10,7 @@
10
10
  "repository": "vaadin/vaadin-combo-box",
11
11
  "homepage": "https://vaadin.com/components",
12
12
  "name": "@vaadin/vaadin-combo-box",
13
- "version": "5.4.11",
13
+ "version": "5.4.13",
14
14
  "main": "vaadin-combo-box.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -25,39 +25,40 @@
25
25
  "theme"
26
26
  ],
27
27
  "resolutions": {
28
- "es-abstract": "1.17.6",
29
- "@types/doctrine": "0.0.3",
30
28
  "inherits": "2.0.3",
31
29
  "samsam": "1.1.3",
32
30
  "supports-color": "3.1.2",
33
31
  "type-detect": "1.0.0"
34
32
  },
35
33
  "dependencies": {
36
- "@polymer/iron-a11y-announcer": "^3.0.0",
37
34
  "@polymer/iron-a11y-keys-behavior": "^3.0.0",
35
+ "@polymer/iron-a11y-announcer": "^3.0.0",
38
36
  "@polymer/iron-list": "^3.0.0",
39
37
  "@polymer/iron-resizable-behavior": "^3.0.0",
40
38
  "@polymer/polymer": "^3.0.0",
41
39
  "@vaadin/vaadin-control-state-mixin": "^2.2.2",
42
- "@vaadin/vaadin-element-mixin": "^2.4.1",
43
- "@vaadin/vaadin-item": "^2.3.0",
44
- "@vaadin/vaadin-lumo-styles": "^1.1.1",
45
- "@vaadin/vaadin-material-styles": "^1.1.2",
46
40
  "@vaadin/vaadin-overlay": "^3.5.0",
47
41
  "@vaadin/vaadin-text-field": "^2.8.0",
48
- "@vaadin/vaadin-themable-mixin": "^1.6.1"
49
- },
50
- "scripts": {
51
- "generate-typings": "gen-typescript-declarations --outDir . --verify"
42
+ "@vaadin/vaadin-themable-mixin": "^1.6.1",
43
+ "@vaadin/vaadin-lumo-styles": "^1.1.1",
44
+ "@vaadin/vaadin-material-styles": "^1.1.2",
45
+ "@vaadin/vaadin-item": "^2.3.0",
46
+ "@vaadin/vaadin-element-mixin": "^2.4.1"
52
47
  },
53
48
  "devDependencies": {
54
- "@polymer/iron-component-page": "^4.0.0",
49
+ "@web-padawan/gen-typescript-declarations": "^1.6.2",
50
+ "web-component-tester": "6.9.2",
55
51
  "@polymer/iron-form": "^3.0.0",
52
+ "@polymer/iron-component-page": "^4.0.0",
56
53
  "@polymer/iron-test-helpers": "^3.0.0",
57
54
  "@polymer/paper-input": "^3.0.0",
58
55
  "@vaadin/vaadin-button": "^2.4.0",
56
+ "wct-browser-legacy": "^1.0.1",
59
57
  "@vaadin/vaadin-demo-helpers": "^3.1.0",
60
- "@vaadin/vaadin-dialog": "^2.5.0",
61
- "wct-browser-legacy": "^1.0.1"
58
+ "@vaadin/vaadin-dialog": "^2.5.0"
59
+ },
60
+ "scripts": {
61
+ "generate-typings": "gen-typescript-declarations --outDir . --verify",
62
+ "test": "wct --npm"
62
63
  }
63
64
  }
@@ -85,6 +85,11 @@ declare class ComboBoxLightElement extends
85
85
  ready(): void;
86
86
  connectedCallback(): void;
87
87
  disconnectedCallback(): void;
88
+
89
+ /**
90
+ * Returns true if the current input value satisfies all constraints (if any).
91
+ */
92
+ checkValidity(): boolean;
88
93
  }
89
94
 
90
95
  declare global {
@@ -132,6 +132,17 @@ class ComboBoxLightElement extends
132
132
  return this.getRootNode().activeElement === this.inputElement;
133
133
  }
134
134
 
135
+ /**
136
+ * Returns true if the current input value satisfies all constraints (if any).
137
+ * @return {boolean}
138
+ */
139
+ checkValidity() {
140
+ if (this.inputElement && this.inputElement.validate) {
141
+ return this.inputElement.validate();
142
+ }
143
+ return super.checkValidity();
144
+ }
145
+
135
146
  /** @protected */
136
147
  connectedCallback() {
137
148
  super.connectedCallback();
@@ -704,13 +704,19 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
704
704
  }
705
705
  } else {
706
706
  const toLowerCase = (item) => item && item.toLowerCase && item.toLowerCase();
707
- const itemsMatchedByLabel = this.filteredItems
708
- && this.filteredItems.filter(item => toLowerCase(this._getItemLabel(item)) === toLowerCase(this._inputElementValue))
709
- || [];
707
+
708
+ // Try to find an item whose label matches the input value. A matching item is searched from
709
+ // the filteredItems array (if available) and the selectedItem (if available).
710
+ const itemMatchingByLabel = [...(this.filteredItems || []), this.selectedItem].filter((item) => {
711
+ return toLowerCase(this._getItemLabel(item)) === toLowerCase(this._inputElementValue);
712
+ })[0];
713
+
710
714
  if (this.allowCustomValue
711
715
  // to prevent a repetitive input value being saved after pressing ESC and Tab.
712
- && !itemsMatchedByLabel.length) {
716
+ && !itemMatchingByLabel) {
713
717
 
718
+ // An item matching by label was not found, but custom values are allowed.
719
+ // Dispatch a custom-value-set event with the input value.
714
720
  const e = new CustomEvent('custom-value-set', {detail: this._inputElementValue, composed: true, cancelable: true, bubbles: true});
715
721
  this.dispatchEvent(e);
716
722
  if (!e.defaultPrevented) {
@@ -718,9 +724,11 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
718
724
  this._selectItemForValue(customValue);
719
725
  this.value = customValue;
720
726
  }
721
- } else if (!this.allowCustomValue && !this.opened && itemsMatchedByLabel.length > 0) {
722
- this.value = this._getItemValue(itemsMatchedByLabel[0]);
727
+ } else if (!this.allowCustomValue && !this.opened && itemMatchingByLabel) {
728
+ // An item matching by label was found, select it.
729
+ this.value = this._getItemValue(itemMatchingByLabel);
723
730
  } else {
731
+ // Revert the input value
724
732
  this._inputElementValue = this.selectedItem ? this._getItemLabel(this.selectedItem) : (this.value || '');
725
733
  }
726
734
  }
@@ -904,6 +912,7 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
904
912
  /** @private */
905
913
  _detectAndDispatchChange() {
906
914
  if (this.value !== this._lastCommittedValue) {
915
+ this.validate();
907
916
  this.dispatchEvent(new CustomEvent('change', {bubbles: true}));
908
917
  this._lastCommittedValue = this.value;
909
918
  }
@@ -1068,6 +1077,7 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
1068
1077
  }
1069
1078
  if (!this.readonly && !this._closeOnBlurIsPrevented) {
1070
1079
  this._closeOrCommit();
1080
+ this.validate();
1071
1081
  }
1072
1082
  }
1073
1083
 
@@ -1097,8 +1107,8 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
1097
1107
  * @return {boolean | undefined}
1098
1108
  */
1099
1109
  checkValidity() {
1100
- if (this.inputElement.validate) {
1101
- return this.inputElement.validate();
1110
+ if (this.inputElement.checkValidity) {
1111
+ return this.inputElement.checkValidity();
1102
1112
  }
1103
1113
  }
1104
1114
 
@@ -229,7 +229,7 @@ class ComboBoxElement extends
229
229
  }
230
230
 
231
231
  static get version() {
232
- return '5.4.11';
232
+ return '5.4.13';
233
233
  }
234
234
 
235
235
  static get properties() {
@@ -351,6 +351,13 @@ class ComboBoxElement extends
351
351
  ready() {
352
352
  super.ready();
353
353
 
354
+ // Disable the internal text-field's validation to prevent it from overriding
355
+ // the invalid state that was propagated to the text-field from the combo-box.
356
+ this.inputElement.validate = () => {};
357
+ // Restore the internal text-field's invalid state in case
358
+ // it got overridden before the validation was disabled above.
359
+ this.inputElement.invalid = this.invalid;
360
+
354
361
  this._nativeInput = this.inputElement.focusElement;
355
362
  this._toggleElement = this.$.toggleButton;
356
363
  this._clearElement = this.inputElement.shadowRoot.querySelector('[part="clear-button"]');