@vaadin/field-base 23.2.0-alpha6 → 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 +3 -3
- package/src/field-aria-controller.js +1 -1
- package/src/helper-controller.d.ts +1 -1
- package/src/helper-controller.js +1 -1
- package/src/input-constraints-mixin.js +4 -3
- package/src/input-mixin.d.ts +7 -1
- package/src/input-mixin.js +35 -16
- package/src/utils.d.ts +0 -16
- package/src/utils.js +0 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/field-base",
|
|
3
|
-
"version": "23.2.0-
|
|
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-
|
|
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": "
|
|
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 '
|
|
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:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
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
6
|
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
package/src/helper-controller.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
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
6
|
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
@@ -79,9 +79,10 @@ export const InputConstraintsMixin = dedupingMixin(
|
|
|
79
79
|
* @protected
|
|
80
80
|
*/
|
|
81
81
|
_constraintsChanged(...constraints) {
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
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
|
|
package/src/input-mixin.d.ts
CHANGED
|
@@ -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(
|
|
56
|
+
protected _toggleHasValue(hasValue: boolean): void;
|
|
51
57
|
|
|
52
58
|
protected _valueChanged(value?: string, oldValue?: string): void;
|
|
53
59
|
}
|
package/src/input-mixin.js
CHANGED
|
@@ -68,8 +68,8 @@ export const InputMixin = dedupingMixin(
|
|
|
68
68
|
constructor() {
|
|
69
69
|
super();
|
|
70
70
|
|
|
71
|
-
this._boundOnInput = this.
|
|
72
|
-
this._boundOnChange = this.
|
|
71
|
+
this._boundOnInput = this.__onInput.bind(this);
|
|
72
|
+
this._boundOnChange = this._onChange.bind(this);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -147,6 +147,22 @@ export const InputMixin = dedupingMixin(
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* An input event listener used to update `_hasInputValue` property.
|
|
152
|
+
* Do not override this method.
|
|
153
|
+
*
|
|
154
|
+
* @param {Event} event
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
__onInput(event) {
|
|
158
|
+
// In the case a custom web component is passed as `inputElement`,
|
|
159
|
+
// the actual native input element, on which the event occurred,
|
|
160
|
+
// can be inside shadow trees.
|
|
161
|
+
const target = event.composedPath()[0];
|
|
162
|
+
this._hasInputValue = target.value.length > 0;
|
|
163
|
+
this._onInput(event);
|
|
164
|
+
}
|
|
165
|
+
|
|
150
166
|
/**
|
|
151
167
|
* An input event listener used to update the field value.
|
|
152
168
|
*
|
|
@@ -154,9 +170,13 @@ export const InputMixin = dedupingMixin(
|
|
|
154
170
|
* @protected
|
|
155
171
|
*/
|
|
156
172
|
_onInput(event) {
|
|
173
|
+
// In the case a custom web component is passed as `inputElement`,
|
|
174
|
+
// the actual native input element, on which the event occurred,
|
|
175
|
+
// can be inside shadow trees.
|
|
176
|
+
const target = event.composedPath()[0];
|
|
157
177
|
// Ignore fake input events e.g. used by clear button.
|
|
158
178
|
this.__userInput = event.isTrusted;
|
|
159
|
-
this.value =
|
|
179
|
+
this.value = target.value;
|
|
160
180
|
this.__userInput = false;
|
|
161
181
|
}
|
|
162
182
|
|
|
@@ -168,20 +188,9 @@ export const InputMixin = dedupingMixin(
|
|
|
168
188
|
*/
|
|
169
189
|
_onChange(_event) {}
|
|
170
190
|
|
|
171
|
-
/**
|
|
172
|
-
* A change event listener used to update `_hasInputValue` property.
|
|
173
|
-
* Do not override this method.
|
|
174
|
-
*
|
|
175
|
-
* @param {Event} event
|
|
176
|
-
* @private
|
|
177
|
-
*/
|
|
178
|
-
__onChange(event) {
|
|
179
|
-
this._hasInputValue = event.target.value.length > 0;
|
|
180
|
-
this._onChange(event);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
191
|
/**
|
|
184
192
|
* Toggle the has-value attribute based on the value property.
|
|
193
|
+
*
|
|
185
194
|
* @param {boolean} hasValue
|
|
186
195
|
* @protected
|
|
187
196
|
*/
|
|
@@ -196,7 +205,7 @@ export const InputMixin = dedupingMixin(
|
|
|
196
205
|
* @protected
|
|
197
206
|
*/
|
|
198
207
|
_valueChanged(newVal, oldVal) {
|
|
199
|
-
this._toggleHasValue(
|
|
208
|
+
this._toggleHasValue(this._hasValue);
|
|
200
209
|
|
|
201
210
|
// Setting initial value to empty string, do nothing.
|
|
202
211
|
if (newVal === '' && oldVal === undefined) {
|
|
@@ -211,5 +220,15 @@ export const InputMixin = dedupingMixin(
|
|
|
211
220
|
// Setting a value programmatically, sync it to input element.
|
|
212
221
|
this._forwardInputValue(newVal);
|
|
213
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
|
+
}
|
|
214
233
|
},
|
|
215
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
|
-
}
|