@vaadin/field-base 23.2.0-beta2 → 23.2.0-beta3

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/field-base",
3
- "version": "23.2.0-beta2",
3
+ "version": "23.2.0-beta3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "23.2.0-beta2",
35
+ "@vaadin/component-base": "23.2.0-beta3",
36
36
  "lit": "^2.0.0"
37
37
  },
38
38
  "devDependencies": {
@@ -40,5 +40,5 @@
40
40
  "@vaadin/testing-helpers": "^0.3.2",
41
41
  "sinon": "^13.0.2"
42
42
  },
43
- "gitHead": "42864949ade7e573ac534a64ecdd97fab32a87fc"
43
+ "gitHead": "3389e7d2dd4c94c6354817d4dc8c8d2db48c7137"
44
44
  }
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { addValueToAttribute, removeValueFromAttribute } from './utils.js';
6
+ import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
7
7
 
8
8
  /**
9
9
  * A controller for managing ARIA attributes for a field element:
@@ -79,9 +79,10 @@ export const InputConstraintsMixin = dedupingMixin(
79
79
  * @protected
80
80
  */
81
81
  _constraintsChanged(...constraints) {
82
- // Prevent marking field as invalid when setting required state
83
- // or any other constraint before a user has entered the value.
84
- if (!this.invalid) {
82
+ // Validate the field on constraint change only if it has a value.
83
+ // The exception is the case when the field is invalid. In that case,
84
+ // let the method reset `invalid` when the last constraint is removed.
85
+ if (!this.invalid && !this._hasValue) {
85
86
  return;
86
87
  }
87
88
 
@@ -28,6 +28,12 @@ export declare class InputMixinClass {
28
28
  */
29
29
  value: string;
30
30
 
31
+ /**
32
+ * Indicates whether the value is different from the default one.
33
+ * Override if the `value` property has a type other than `string`.
34
+ */
35
+ protected readonly _hasValue: boolean;
36
+
31
37
  /**
32
38
  * Clear the value of the field.
33
39
  */
@@ -47,7 +53,7 @@ export declare class InputMixinClass {
47
53
 
48
54
  protected _setInputElement(input: HTMLElement): void;
49
55
 
50
- protected _toggleHasValue(value: boolean): void;
56
+ protected _toggleHasValue(hasValue: boolean): void;
51
57
 
52
58
  protected _valueChanged(value?: string, oldValue?: string): void;
53
59
  }
@@ -190,6 +190,7 @@ export const InputMixin = dedupingMixin(
190
190
 
191
191
  /**
192
192
  * Toggle the has-value attribute based on the value property.
193
+ *
193
194
  * @param {boolean} hasValue
194
195
  * @protected
195
196
  */
@@ -204,7 +205,7 @@ export const InputMixin = dedupingMixin(
204
205
  * @protected
205
206
  */
206
207
  _valueChanged(newVal, oldVal) {
207
- this._toggleHasValue(newVal !== '' && newVal != null);
208
+ this._toggleHasValue(this._hasValue);
208
209
 
209
210
  // Setting initial value to empty string, do nothing.
210
211
  if (newVal === '' && oldVal === undefined) {
@@ -219,5 +220,15 @@ export const InputMixin = dedupingMixin(
219
220
  // Setting a value programmatically, sync it to input element.
220
221
  this._forwardInputValue(newVal);
221
222
  }
223
+
224
+ /**
225
+ * Indicates whether the value is different from the default one.
226
+ * Override if the `value` property has a type other than `string`.
227
+ *
228
+ * @protected
229
+ */
230
+ get _hasValue() {
231
+ return this.value != null && this.value !== '';
232
+ }
222
233
  },
223
234
  );
package/src/utils.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * Adds a value to an attribute containing space-delimited values.
9
- */
10
- export declare function addValueToAttribute(element: HTMLElement, attr: string, value: string): void;
11
-
12
- /**
13
- * Removes a value from an attribute containing space-delimited values.
14
- * If the value is the last one, the whole attribute is removed.
15
- */
16
- export declare function removeValueFromAttribute(element: HTMLElement, attr: string, value: string): void;
package/src/utils.js DELETED
@@ -1,56 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * @param {string} value
9
- * @return {Set<string>}
10
- */
11
- function deserializeAttributeValue(value) {
12
- if (!value) {
13
- return new Set();
14
- }
15
-
16
- return new Set(value.split(' '));
17
- }
18
-
19
- /**
20
- * @param {Set<string>} values
21
- * @return {string}
22
- */
23
- function serializeAttributeValue(values) {
24
- return [...values].join(' ');
25
- }
26
-
27
- /**
28
- * Adds a value to an attribute containing space-delimited values.
29
- *
30
- * @param {HTMLElement} element
31
- * @param {string} attr
32
- * @param {string} value
33
- */
34
- export function addValueToAttribute(element, attr, value) {
35
- const values = deserializeAttributeValue(element.getAttribute(attr));
36
- values.add(value);
37
- element.setAttribute(attr, serializeAttributeValue(values));
38
- }
39
-
40
- /**
41
- * Removes a value from an attribute containing space-delimited values.
42
- * If the value is the last one, the whole attribute is removed.
43
- *
44
- * @param {HTMLElement} element
45
- * @param {string} attr
46
- * @param {string} value
47
- */
48
- export function removeValueFromAttribute(element, attr, value) {
49
- const values = deserializeAttributeValue(element.getAttribute(attr));
50
- values.delete(value);
51
- if (values.size === 0) {
52
- element.removeAttribute(attr);
53
- return;
54
- }
55
- element.setAttribute(attr, serializeAttributeValue(values));
56
- }