@vaadin/vaadin-combo-box 5.4.12 → 5.5.0

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.12",
13
+ "version": "5.5.0",
14
14
  "main": "vaadin-combo-box.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -45,10 +45,6 @@
45
45
  "@vaadin/vaadin-item": "^2.3.0",
46
46
  "@vaadin/vaadin-element-mixin": "^2.4.1"
47
47
  },
48
- "scripts": {
49
- "generate-typings": "gen-typescript-declarations --outDir . --verify",
50
- "test": "wct --npm"
51
- },
52
48
  "devDependencies": {
53
49
  "@web-padawan/gen-typescript-declarations": "^1.6.2",
54
50
  "web-component-tester": "6.9.2",
@@ -60,5 +56,9 @@
60
56
  "wct-browser-legacy": "^1.0.1",
61
57
  "@vaadin/vaadin-demo-helpers": "^3.1.0",
62
58
  "@vaadin/vaadin-dialog": "^2.5.0"
59
+ },
60
+ "scripts": {
61
+ "generate-typings": "gen-typescript-declarations --outDir . --verify",
62
+ "test": "wct --npm"
63
63
  }
64
64
  }
@@ -122,6 +122,11 @@ interface ComboBoxMixin {
122
122
  */
123
123
  selectedItem: ComboBoxItem|string|null|undefined;
124
124
 
125
+ /**
126
+ * Whether the input element has a non-empty value.
127
+ */
128
+ _hasInputValue: boolean|null|undefined;
129
+
125
130
  /**
126
131
  * Path for label of the item. If `items` is an array of objects, the
127
132
  * `itemLabelPath` is used to fetch the displayed string label for each
@@ -201,10 +206,19 @@ interface ComboBoxMixin {
201
206
  * Filtering and items handling
202
207
  */
203
208
  _inputValueChanged(e: Event): void;
209
+ _inputElementValueChanged(inputElementValue: any): void;
204
210
  _revertInputValue(): void;
211
+ _setInvalid(invalid: boolean): void;
205
212
 
206
213
  /**
207
- * Returns true if `value` is valid, and sets the `invalid` flag appropriately.
214
+ * Override this method to define whether the given `invalid` state should be set.
215
+ */
216
+ _shouldSetInvalid(_invalid: boolean): boolean;
217
+
218
+ /**
219
+ * Validates the field and sets the `invalid` property based on the result.
220
+ *
221
+ * The method fires a `validated` event with the result of the validation.
208
222
  *
209
223
  * @returns True if the value is valid and sets the `invalid` flag appropriately
210
224
  */
@@ -166,6 +166,16 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
166
166
  notify: true
167
167
  },
168
168
 
169
+ /**
170
+ * Whether the input element has a non-empty value.
171
+ * @protected
172
+ */
173
+ _hasInputValue: {
174
+ type: Boolean,
175
+ value: false,
176
+ observer: '_hasInputValueChanged',
177
+ },
178
+
169
179
  /**
170
180
  * Path for label of the item. If `items` is an array of objects, the
171
181
  * `itemLabelPath` is used to fetch the displayed string label for each
@@ -261,7 +271,8 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
261
271
  '_templateOrRendererChanged(_itemTemplate, renderer)',
262
272
  '_loadingChanged(loading)',
263
273
  '_selectedItemChanged(selectedItem, itemValuePath, itemLabelPath)',
264
- '_toggleElementChanged(_toggleElement)'
274
+ '_toggleElementChanged(_toggleElement)',
275
+ '_inputElementValueChanged(_inputElementValue)'
265
276
  ];
266
277
  }
267
278
 
@@ -632,6 +643,7 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
632
643
  this.selectedItem = null;
633
644
 
634
645
  if (this.allowCustomValue) {
646
+ this._inputElementValue = '';
635
647
  this.value = '';
636
648
  }
637
649
 
@@ -763,6 +775,10 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
763
775
  }
764
776
  }
765
777
 
778
+ _inputElementValueChanged(inputElementValue) {
779
+ this._hasInputValue = inputElementValue != null ? inputElementValue.length > 0 : false;
780
+ }
781
+
766
782
  /** @private */
767
783
  _filterFromInput(e) {
768
784
  if (!this.opened && !e.__fromClearButton && !this.autoOpenDisabled) {
@@ -1090,12 +1106,49 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
1090
1106
  }
1091
1107
 
1092
1108
  /**
1093
- * Returns true if `value` is valid, and sets the `invalid` flag appropriately.
1109
+ * Observer to notify about the change of private property.
1110
+ *
1111
+ * @private
1112
+ */
1113
+ _hasInputValueChanged(hasValue, oldHasValue) {
1114
+ if (hasValue || oldHasValue) {
1115
+ this.dispatchEvent(new CustomEvent('has-input-value-changed'));
1116
+ }
1117
+ }
1118
+
1119
+ /**
1120
+ * @param {boolean} invalid
1121
+ * @protected
1122
+ */
1123
+ _setInvalid(invalid) {
1124
+ if (this._shouldSetInvalid(invalid)) {
1125
+ this.invalid = invalid;
1126
+ }
1127
+ }
1128
+
1129
+ /**
1130
+ * Override this method to define whether the given `invalid` state should be set.
1131
+ *
1132
+ * @param {boolean} _invalid
1133
+ * @return {boolean}
1134
+ * @protected
1135
+ */
1136
+ _shouldSetInvalid(_invalid) {
1137
+ return true;
1138
+ }
1139
+
1140
+ /**
1141
+ * Validates the field and sets the `invalid` property based on the result.
1142
+ *
1143
+ * The method fires a `validated` event with the result of the validation.
1094
1144
  *
1095
1145
  * @return {boolean} True if the value is valid and sets the `invalid` flag appropriately
1096
1146
  */
1097
1147
  validate() {
1098
- return !(this.invalid = !this.checkValidity());
1148
+ const isValid = this.checkValidity();
1149
+ this._setInvalid(!isValid);
1150
+ this.dispatchEvent(new CustomEvent('validated', {detail: {valid: isValid}}));
1151
+ return isValid;
1099
1152
  }
1100
1153
 
1101
1154
  /**
@@ -1206,4 +1259,12 @@ export const ComboBoxMixin = subclass => class VaadinComboBoxMixinElement extend
1206
1259
  * To comply with https://developer.mozilla.org/en-US/docs/Web/Events/change
1207
1260
  * @event change
1208
1261
  */
1262
+
1263
+ /**
1264
+ * Fired whenever the field is validated.
1265
+ *
1266
+ * @event validated
1267
+ * @param {Object} detail
1268
+ * @param {boolean} detail.valid the result of the validation.
1269
+ */
1209
1270
  };
@@ -229,7 +229,7 @@ class ComboBoxElement extends
229
229
  }
230
230
 
231
231
  static get version() {
232
- return '5.4.12';
232
+ return '5.5.0';
233
233
  }
234
234
 
235
235
  static get properties() {