@vaadin/field-base 25.1.2 → 25.2.0-alpha10
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/custom-elements.json +1141 -13
- package/package.json +7 -7
- package/src/field-mixin.js +1 -1
- package/src/input-constraints-mixin.js +100 -99
- package/src/input-control-mixin.js +0 -13
- package/src/input-mixin.js +208 -207
- package/src/label-mixin.js +1 -1
- package/src/validate-mixin.js +86 -94
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/field-base",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.2.0-alpha10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
35
|
-
"@vaadin/a11y-base": "
|
|
36
|
-
"@vaadin/component-base": "
|
|
35
|
+
"@vaadin/a11y-base": "25.2.0-alpha10",
|
|
36
|
+
"@vaadin/component-base": "25.2.0-alpha10",
|
|
37
37
|
"lit": "^3.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@vaadin/chai-plugins": "
|
|
41
|
-
"@vaadin/input-container": "
|
|
42
|
-
"@vaadin/test-runner-commands": "
|
|
40
|
+
"@vaadin/chai-plugins": "25.2.0-alpha10",
|
|
41
|
+
"@vaadin/input-container": "25.2.0-alpha10",
|
|
42
|
+
"@vaadin/test-runner-commands": "25.2.0-alpha10",
|
|
43
43
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
44
44
|
"sinon": "^21.0.2"
|
|
45
45
|
},
|
|
46
46
|
"customElements": "custom-elements.json",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1303b6a3eeecb44a9d26f2b53cb56d9e906febdf"
|
|
48
48
|
}
|
package/src/field-mixin.js
CHANGED
|
@@ -200,7 +200,7 @@ export const FieldMixin = (superclass) =>
|
|
|
200
200
|
// Otherwise assistive technologies would announce the error, even if we hide it.
|
|
201
201
|
if (invalid) {
|
|
202
202
|
const node = this._errorNode;
|
|
203
|
-
this._fieldAriaController.setErrorId(node
|
|
203
|
+
this._fieldAriaController.setErrorId(node?.id);
|
|
204
204
|
} else {
|
|
205
205
|
this._fieldAriaController.setErrorId(null);
|
|
206
206
|
}
|
|
@@ -16,116 +16,117 @@ import { ValidateMixin } from './validate-mixin.js';
|
|
|
16
16
|
* @mixes InputMixin
|
|
17
17
|
* @mixes ValidateMixin
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
(superclass)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
19
|
+
const InputConstraintsMixinImplementation = (superclass) => {
|
|
20
|
+
return class InputConstraintsMixinClass extends DelegateStateMixin(ValidateMixin(InputMixin(superclass))) {
|
|
21
|
+
/**
|
|
22
|
+
* An array of attributes which participate in the input validation.
|
|
23
|
+
* Changing these attributes will cause the input to re-validate.
|
|
24
|
+
*
|
|
25
|
+
* IMPORTANT: The attributes should be properly delegated to the input element
|
|
26
|
+
* from the host using `delegateAttrs` getter (see `DelegateStateMixin`).
|
|
27
|
+
* The `required` attribute is already delegated.
|
|
28
|
+
*/
|
|
29
|
+
static get constraints() {
|
|
30
|
+
return ['required'];
|
|
31
|
+
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
static get delegateAttrs() {
|
|
34
|
+
return [...super.delegateAttrs, 'required'];
|
|
35
|
+
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
/** @protected */
|
|
38
|
+
ready() {
|
|
39
|
+
super.ready();
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
this._createConstraintsObserver();
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return !this.invalid;
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the current input value satisfies all constraints (if any).
|
|
46
|
+
* @return {boolean}
|
|
47
|
+
*/
|
|
48
|
+
checkValidity() {
|
|
49
|
+
if (this.inputElement && this._hasValidConstraints(this.constructor.constraints.map((c) => this[c]))) {
|
|
50
|
+
return this.inputElement.checkValidity();
|
|
54
51
|
}
|
|
52
|
+
return !this.invalid;
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if some of the provided set of constraints are valid.
|
|
57
|
+
* @param {Array} constraints
|
|
58
|
+
* @return {boolean}
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
_hasValidConstraints(constraints) {
|
|
62
|
+
return constraints.some((c) => this.__isValidConstraint(c));
|
|
63
|
+
}
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Override this method to customize setting up constraints observer.
|
|
67
|
+
* @protected
|
|
68
|
+
*/
|
|
69
|
+
_createConstraintsObserver() {
|
|
70
|
+
// This complex observer needs to be added dynamically instead of using `static get observers()`
|
|
71
|
+
// to make it possible to tweak this behavior in classes that apply this mixin.
|
|
72
|
+
this._createMethodObserver(`_constraintsChanged(stateTarget, ${this.constructor.constraints.join(', ')})`);
|
|
73
|
+
}
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const hasConstraints = this._hasValidConstraints(constraints);
|
|
90
|
-
const isLastConstraintRemoved = this.__previousHasConstraints && !hasConstraints;
|
|
91
|
-
|
|
92
|
-
if ((this._hasValue || this.invalid) && hasConstraints) {
|
|
93
|
-
this._requestValidation();
|
|
94
|
-
} else if (isLastConstraintRemoved && !this.manualValidation) {
|
|
95
|
-
this._setInvalid(false);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.__previousHasConstraints = hasConstraints;
|
|
75
|
+
/**
|
|
76
|
+
* Override this method to implement custom validation constraints.
|
|
77
|
+
* @param {HTMLElement | undefined} stateTarget
|
|
78
|
+
* @param {unknown[]} constraints
|
|
79
|
+
* @protected
|
|
80
|
+
*/
|
|
81
|
+
_constraintsChanged(stateTarget, ...constraints) {
|
|
82
|
+
// The input element's validity cannot be determined until
|
|
83
|
+
// all the necessary constraint attributes aren't set on it.
|
|
84
|
+
if (!stateTarget) {
|
|
85
|
+
return;
|
|
99
86
|
}
|
|
100
87
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* to capture native `change` event and make sure that
|
|
104
|
-
* a new one is dispatched after validation runs.
|
|
105
|
-
* @param {Event} event
|
|
106
|
-
* @protected
|
|
107
|
-
* @override
|
|
108
|
-
*/
|
|
109
|
-
_onChange(event) {
|
|
110
|
-
event.stopPropagation();
|
|
88
|
+
const hasConstraints = this._hasValidConstraints(constraints);
|
|
89
|
+
const isLastConstraintRemoved = this.__previousHasConstraints && !hasConstraints;
|
|
111
90
|
|
|
91
|
+
if ((this._hasValue || this.invalid) && hasConstraints) {
|
|
112
92
|
this._requestValidation();
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
new CustomEvent('change', {
|
|
116
|
-
detail: {
|
|
117
|
-
sourceEvent: event,
|
|
118
|
-
},
|
|
119
|
-
bubbles: event.bubbles,
|
|
120
|
-
cancelable: event.cancelable,
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
93
|
+
} else if (isLastConstraintRemoved && !this.manualValidation) {
|
|
94
|
+
this._setInvalid(false);
|
|
123
95
|
}
|
|
124
96
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
97
|
+
this.__previousHasConstraints = hasConstraints;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Override an event listener inherited from `InputMixin`
|
|
102
|
+
* to capture native `change` event and make sure that
|
|
103
|
+
* a new one is dispatched after validation runs.
|
|
104
|
+
* @param {Event} event
|
|
105
|
+
* @protected
|
|
106
|
+
* @override
|
|
107
|
+
*/
|
|
108
|
+
_onChange(event) {
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
|
|
111
|
+
this._requestValidation();
|
|
112
|
+
|
|
113
|
+
this.dispatchEvent(
|
|
114
|
+
new CustomEvent('change', {
|
|
115
|
+
detail: {
|
|
116
|
+
sourceEvent: event,
|
|
117
|
+
},
|
|
118
|
+
bubbles: event.bubbles,
|
|
119
|
+
cancelable: event.cancelable,
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** @private */
|
|
125
|
+
__isValidConstraint(constraint) {
|
|
126
|
+
// 0 is valid for `minlength` and `maxlength`
|
|
127
|
+
return Boolean(constraint) || constraint === 0;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const InputConstraintsMixin = dedupeMixin(InputConstraintsMixinImplementation);
|
|
@@ -250,17 +250,4 @@ export const InputControlMixin = (superclass) =>
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Fired when the user commits a value change.
|
|
256
|
-
*
|
|
257
|
-
* @event change
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Fired when the value is changed by the user: on every typing keystroke,
|
|
262
|
-
* and the value is cleared using the clear button.
|
|
263
|
-
*
|
|
264
|
-
* @event input
|
|
265
|
-
*/
|
|
266
253
|
};
|