@vaadin/field-base 25.2.0-alpha1 → 25.2.0-alpha11
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/checked-mixin.js +0 -5
- package/src/clear-button-mixin.js +0 -4
- package/src/error-controller.d.ts +2 -0
- package/src/field-mixin.js +1 -5
- package/src/helper-controller.d.ts +2 -0
- package/src/input-constraints-mixin.js +100 -104
- package/src/input-control-mixin.js +0 -21
- package/src/input-controller.d.ts +3 -1
- package/src/input-field-mixin.js +0 -3
- package/src/input-mixin.js +208 -209
- package/src/label-controller.d.ts +2 -0
- package/src/label-mixin.js +1 -3
- package/src/labelled-input-controller.d.ts +17 -1
- package/src/pattern-mixin.js +0 -3
- package/src/styles/button-base-styles.js +2 -2
- package/src/text-area-controller.d.ts +3 -1
- package/src/validate-mixin.js +86 -96
- package/src/virtual-keyboard-controller.d.ts +8 -0
package/src/input-mixin.js
CHANGED
|
@@ -8,222 +8,221 @@ import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
|
8
8
|
/**
|
|
9
9
|
* A mixin to store the reference to an input element
|
|
10
10
|
* and add input and change event listeners to it.
|
|
11
|
-
*
|
|
12
|
-
* @polymerMixin
|
|
13
11
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
type:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
12
|
+
const InputMixinImplementation = (superclass) => {
|
|
13
|
+
return class InputMixinClass extends superclass {
|
|
14
|
+
static get properties() {
|
|
15
|
+
return {
|
|
16
|
+
/**
|
|
17
|
+
* A reference to the input element controlled by the mixin.
|
|
18
|
+
* Any component implementing this mixin is expected to provide it
|
|
19
|
+
* by using `this._setInputElement(input)` API. A typical case is
|
|
20
|
+
* using `InputController` that does this automatically.
|
|
21
|
+
*
|
|
22
|
+
* @protected
|
|
23
|
+
* @type {!HTMLElement}
|
|
24
|
+
*/
|
|
25
|
+
inputElement: {
|
|
26
|
+
type: Object,
|
|
27
|
+
readOnly: true,
|
|
28
|
+
observer: '_inputElementChanged',
|
|
29
|
+
sync: true,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* String used to define input type.
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
type: {
|
|
37
|
+
type: String,
|
|
38
|
+
readOnly: true,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The value of the field.
|
|
43
|
+
*/
|
|
44
|
+
value: {
|
|
45
|
+
type: String,
|
|
46
|
+
value: '',
|
|
47
|
+
observer: '_valueChanged',
|
|
48
|
+
notify: true,
|
|
49
|
+
sync: true,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
constructor() {
|
|
55
|
+
super();
|
|
56
|
+
|
|
57
|
+
this._boundOnInput = this._onInput.bind(this);
|
|
58
|
+
this._boundOnChange = this._onChange.bind(this);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Indicates whether the value is different from the default one.
|
|
63
|
+
* Override if the `value` property has a type other than `string`.
|
|
64
|
+
*
|
|
65
|
+
* @protected
|
|
66
|
+
*/
|
|
67
|
+
get _hasValue() {
|
|
68
|
+
return this.value != null && this.value !== '';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A property for accessing the input element's value.
|
|
73
|
+
*
|
|
74
|
+
* Override this getter if the property is different from the default `value` one.
|
|
75
|
+
*
|
|
76
|
+
* @protected
|
|
77
|
+
* @return {string}
|
|
78
|
+
*/
|
|
79
|
+
get _inputElementValueProperty() {
|
|
80
|
+
return 'value';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The input element's value.
|
|
85
|
+
*
|
|
86
|
+
* @protected
|
|
87
|
+
* @return {string}
|
|
88
|
+
*/
|
|
89
|
+
get _inputElementValue() {
|
|
90
|
+
return this.inputElement ? this.inputElement[this._inputElementValueProperty] : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The input element's value.
|
|
95
|
+
*
|
|
96
|
+
* @protected
|
|
97
|
+
*/
|
|
98
|
+
set _inputElementValue(value) {
|
|
99
|
+
if (this.inputElement) {
|
|
100
|
+
this.inputElement[this._inputElementValueProperty] = value;
|
|
55
101
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Clear the value of the field.
|
|
106
|
+
*/
|
|
107
|
+
clear() {
|
|
108
|
+
this.value = '';
|
|
109
|
+
|
|
110
|
+
// Clear the input immediately without waiting for the observer.
|
|
111
|
+
// Otherwise, when using Lit, the old value would be restored.
|
|
112
|
+
this._inputElementValue = '';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Add event listeners to the input element instance.
|
|
117
|
+
* Override this method to add custom listeners.
|
|
118
|
+
* @param {!HTMLElement} input
|
|
119
|
+
* @protected
|
|
120
|
+
*/
|
|
121
|
+
_addInputListeners(input) {
|
|
122
|
+
input.addEventListener('input', this._boundOnInput);
|
|
123
|
+
input.addEventListener('change', this._boundOnChange);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Remove event listeners from the input element instance.
|
|
128
|
+
* @param {!HTMLElement} input
|
|
129
|
+
* @protected
|
|
130
|
+
*/
|
|
131
|
+
_removeInputListeners(input) {
|
|
132
|
+
input.removeEventListener('input', this._boundOnInput);
|
|
133
|
+
input.removeEventListener('change', this._boundOnChange);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A method to forward the value property set on the field
|
|
138
|
+
* programmatically back to the input element value.
|
|
139
|
+
* Override this method to perform additional checks,
|
|
140
|
+
* for example to skip this in certain conditions.
|
|
141
|
+
* @param {string} value
|
|
142
|
+
* @protected
|
|
143
|
+
*/
|
|
144
|
+
_forwardInputValue(value) {
|
|
145
|
+
// Value might be set before an input element is initialized.
|
|
146
|
+
// This case should be handled separately by a component that
|
|
147
|
+
// implements this mixin, for example in `connectedCallback`.
|
|
148
|
+
if (!this.inputElement) {
|
|
149
|
+
return;
|
|
105
150
|
}
|
|
106
151
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
* Override this method to add custom listeners.
|
|
121
|
-
* @param {!HTMLElement} input
|
|
122
|
-
* @protected
|
|
123
|
-
*/
|
|
124
|
-
_addInputListeners(input) {
|
|
125
|
-
input.addEventListener('input', this._boundOnInput);
|
|
126
|
-
input.addEventListener('change', this._boundOnChange);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Remove event listeners from the input element instance.
|
|
131
|
-
* @param {!HTMLElement} input
|
|
132
|
-
* @protected
|
|
133
|
-
*/
|
|
134
|
-
_removeInputListeners(input) {
|
|
135
|
-
input.removeEventListener('input', this._boundOnInput);
|
|
136
|
-
input.removeEventListener('change', this._boundOnChange);
|
|
152
|
+
this._inputElementValue = value != null ? value : '';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param {HTMLElement | undefined} input
|
|
157
|
+
* @param {HTMLElement | undefined} oldInput
|
|
158
|
+
* @protected
|
|
159
|
+
*/
|
|
160
|
+
_inputElementChanged(input, oldInput) {
|
|
161
|
+
if (input) {
|
|
162
|
+
this._addInputListeners(input);
|
|
163
|
+
} else if (oldInput) {
|
|
164
|
+
this._removeInputListeners(oldInput);
|
|
137
165
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* An input event listener used to update the field value.
|
|
170
|
+
*
|
|
171
|
+
* @param {Event} event
|
|
172
|
+
* @protected
|
|
173
|
+
*/
|
|
174
|
+
_onInput(event) {
|
|
175
|
+
// In the case a custom web component is passed as `inputElement`,
|
|
176
|
+
// the actual native input element, on which the event occurred,
|
|
177
|
+
// can be inside shadow trees.
|
|
178
|
+
const target = event.composedPath()[0];
|
|
179
|
+
// Ignore fake input events e.g. used by clear button.
|
|
180
|
+
this.__userInput = event.isTrusted;
|
|
181
|
+
this.value = target.value;
|
|
182
|
+
this.__userInput = false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* A change event listener.
|
|
187
|
+
* Override this method with an actual implementation.
|
|
188
|
+
* @param {Event} _event
|
|
189
|
+
* @protected
|
|
190
|
+
*/
|
|
191
|
+
_onChange(_event) {}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Toggle the has-value attribute based on the value property.
|
|
195
|
+
*
|
|
196
|
+
* @param {boolean} hasValue
|
|
197
|
+
* @protected
|
|
198
|
+
*/
|
|
199
|
+
_toggleHasValue(hasValue) {
|
|
200
|
+
this.toggleAttribute('has-value', hasValue);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Observer called when a value property changes.
|
|
205
|
+
* @param {string | undefined} newVal
|
|
206
|
+
* @param {string | undefined} oldVal
|
|
207
|
+
* @protected
|
|
208
|
+
*/
|
|
209
|
+
_valueChanged(newVal, oldVal) {
|
|
210
|
+
this._toggleHasValue(this._hasValue);
|
|
211
|
+
|
|
212
|
+
// Setting initial value to empty string, do nothing.
|
|
213
|
+
if (newVal === '' && oldVal === undefined) {
|
|
214
|
+
return;
|
|
156
215
|
}
|
|
157
216
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
* @protected
|
|
162
|
-
*/
|
|
163
|
-
_inputElementChanged(input, oldInput) {
|
|
164
|
-
if (input) {
|
|
165
|
-
this._addInputListeners(input);
|
|
166
|
-
} else if (oldInput) {
|
|
167
|
-
this._removeInputListeners(oldInput);
|
|
168
|
-
}
|
|
217
|
+
// Value is set by the user, no need to sync it back to input.
|
|
218
|
+
if (this.__userInput) {
|
|
219
|
+
return;
|
|
169
220
|
}
|
|
170
221
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*/
|
|
177
|
-
_onInput(event) {
|
|
178
|
-
// In the case a custom web component is passed as `inputElement`,
|
|
179
|
-
// the actual native input element, on which the event occurred,
|
|
180
|
-
// can be inside shadow trees.
|
|
181
|
-
const target = event.composedPath()[0];
|
|
182
|
-
// Ignore fake input events e.g. used by clear button.
|
|
183
|
-
this.__userInput = event.isTrusted;
|
|
184
|
-
this.value = target.value;
|
|
185
|
-
this.__userInput = false;
|
|
186
|
-
}
|
|
222
|
+
// Setting a value programmatically, sync it to input element.
|
|
223
|
+
this._forwardInputValue(newVal);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
187
227
|
|
|
188
|
-
|
|
189
|
-
* A change event listener.
|
|
190
|
-
* Override this method with an actual implementation.
|
|
191
|
-
* @param {Event} _event
|
|
192
|
-
* @protected
|
|
193
|
-
*/
|
|
194
|
-
_onChange(_event) {}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Toggle the has-value attribute based on the value property.
|
|
198
|
-
*
|
|
199
|
-
* @param {boolean} hasValue
|
|
200
|
-
* @protected
|
|
201
|
-
*/
|
|
202
|
-
_toggleHasValue(hasValue) {
|
|
203
|
-
this.toggleAttribute('has-value', hasValue);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Observer called when a value property changes.
|
|
208
|
-
* @param {string | undefined} newVal
|
|
209
|
-
* @param {string | undefined} oldVal
|
|
210
|
-
* @protected
|
|
211
|
-
*/
|
|
212
|
-
_valueChanged(newVal, oldVal) {
|
|
213
|
-
this._toggleHasValue(this._hasValue);
|
|
214
|
-
|
|
215
|
-
// Setting initial value to empty string, do nothing.
|
|
216
|
-
if (newVal === '' && oldVal === undefined) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Value is set by the user, no need to sync it back to input.
|
|
221
|
-
if (this.__userInput) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Setting a value programmatically, sync it to input element.
|
|
226
|
-
this._forwardInputValue(newVal);
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
);
|
|
228
|
+
export const InputMixin = dedupeMixin(InputMixinImplementation);
|
|
@@ -9,6 +9,8 @@ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-chil
|
|
|
9
9
|
* A controller to manage the label element.
|
|
10
10
|
*/
|
|
11
11
|
export class LabelController extends SlotChildObserveController {
|
|
12
|
+
constructor(host: HTMLElement);
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* String used for the label.
|
|
14
16
|
*/
|
package/src/label-mixin.js
CHANGED
|
@@ -7,8 +7,6 @@ import { LabelController } from './label-controller.js';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A mixin to provide label via corresponding property or named slot.
|
|
10
|
-
*
|
|
11
|
-
* @polymerMixin
|
|
12
10
|
*/
|
|
13
11
|
export const LabelMixin = (superclass) =>
|
|
14
12
|
class LabelMixinClass extends superclass {
|
|
@@ -38,7 +36,7 @@ export const LabelMixin = (superclass) =>
|
|
|
38
36
|
/** @protected */
|
|
39
37
|
get _labelId() {
|
|
40
38
|
const node = this._labelNode;
|
|
41
|
-
return node
|
|
39
|
+
return node?.id;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
/** @protected */
|
|
@@ -4,8 +4,24 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { ReactiveController } from 'lit';
|
|
7
|
+
import type { LabelController } from './label-controller.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* A controller for linking a `<label>` element with an `<input>` element.
|
|
10
11
|
*/
|
|
11
|
-
export class LabelledInputController implements ReactiveController {
|
|
12
|
+
export class LabelledInputController implements ReactiveController {
|
|
13
|
+
constructor(input: HTMLInputElement, labelController: LabelController);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The input element to link with the label.
|
|
17
|
+
*/
|
|
18
|
+
input: HTMLInputElement;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Phantom optional method to satisfy the `ReactiveController` interface
|
|
22
|
+
* (TS2559: an interface with all-optional members needs at least one
|
|
23
|
+
* declared property in common). Not implemented at runtime; Lit's
|
|
24
|
+
* `addController` invokes it via optional chaining.
|
|
25
|
+
*/
|
|
26
|
+
hostConnected?(): void;
|
|
27
|
+
}
|
package/src/pattern-mixin.js
CHANGED
|
@@ -7,9 +7,6 @@ import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A mixin to provide `pattern` property.
|
|
10
|
-
*
|
|
11
|
-
* @polymerMixin
|
|
12
|
-
* @mixes InputConstraintsMixin
|
|
13
10
|
*/
|
|
14
11
|
export const PatternMixin = (superclass) =>
|
|
15
12
|
class PatternMixinClass extends InputConstraintsMixin(superclass) {
|
|
@@ -15,8 +15,8 @@ export const button = css`
|
|
|
15
15
|
-webkit-user-select: none;
|
|
16
16
|
user-select: none;
|
|
17
17
|
/* Ensure minimum click target (WCAG) */
|
|
18
|
-
padding: max(0px, (24px - 1lh) / 2);
|
|
19
|
-
margin: min(0px, (24px - 1lh) / -2);
|
|
18
|
+
padding: max(0px, (24px - var(--vaadin-icon-size, 1lh)) / 2);
|
|
19
|
+
margin: min(0px, (24px - var(--vaadin-icon-size, 1lh)) / -2);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/* Icon */
|
|
@@ -8,4 +8,6 @@ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
|
8
8
|
/**
|
|
9
9
|
* A controller to create and initialize slotted `<textarea>` element.
|
|
10
10
|
*/
|
|
11
|
-
export class TextAreaController extends SlotController {
|
|
11
|
+
export class TextAreaController extends SlotController {
|
|
12
|
+
constructor(host: HTMLElement, callback?: (node: HTMLTextAreaElement) => void);
|
|
13
|
+
}
|