@vaadin/field-base 22.0.0-alpha5 → 22.0.0-alpha9
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/index.d.ts +7 -15
- package/index.js +7 -15
- package/package.json +24 -18
- package/src/aria-label-controller.d.ts +11 -0
- package/src/aria-label-controller.js +53 -0
- package/src/checked-mixin.d.ts +21 -0
- package/src/checked-mixin.js +54 -0
- package/src/delegate-focus-mixin.d.ts +2 -2
- package/src/delegate-focus-mixin.js +150 -133
- package/src/delegate-state-mixin.d.ts +1 -1
- package/src/delegate-state-mixin.js +100 -88
- package/src/field-mixin.d.ts +39 -0
- package/src/field-mixin.js +317 -0
- package/src/input-constraints-mixin.d.ts +4 -2
- package/src/input-constraints-mixin.js +107 -64
- package/src/input-control-mixin.d.ts +52 -0
- package/src/input-control-mixin.js +170 -0
- package/src/input-controller.d.ts +11 -0
- package/src/input-controller.js +35 -0
- package/src/input-field-mixin.d.ts +2 -16
- package/src/input-field-mixin.js +125 -80
- package/src/input-mixin.d.ts +1 -1
- package/src/input-mixin.js +156 -145
- package/src/label-mixin.d.ts +2 -2
- package/src/label-mixin.js +73 -60
- package/src/pattern-mixin.js +9 -9
- package/src/shadow-focus-mixin.d.ts +21 -0
- package/src/shadow-focus-mixin.js +87 -0
- package/src/slot-controller.d.ts +8 -0
- package/src/slot-controller.js +36 -0
- package/src/slot-label-mixin.d.ts +20 -0
- package/src/slot-label-mixin.js +38 -0
- package/src/slot-styles-mixin.js +38 -31
- package/src/slot-target-mixin.d.ts +32 -0
- package/src/slot-target-mixin.js +110 -0
- package/src/styles/clear-button-styles.d.ts +8 -0
- package/src/styles/clear-button-styles.js +21 -0
- package/src/styles/field-shared-styles.d.ts +8 -0
- package/src/styles/field-shared-styles.js +29 -0
- package/src/styles/input-field-container-styles.d.ts +8 -0
- package/src/styles/input-field-container-styles.js +16 -0
- package/src/styles/input-field-shared-styles.d.ts +8 -0
- package/src/styles/input-field-shared-styles.js +10 -0
- package/src/text-area-controller.d.ts +11 -0
- package/src/text-area-controller.js +38 -0
- package/src/validate-mixin.d.ts +1 -9
- package/src/validate-mixin.js +43 -118
- package/src/active-mixin.d.ts +0 -26
- package/src/active-mixin.js +0 -106
- package/src/aria-label-mixin.d.ts +0 -20
- package/src/aria-label-mixin.js +0 -71
- package/src/char-length-mixin.d.ts +0 -30
- package/src/char-length-mixin.js +0 -42
- package/src/clear-button-mixin.d.ts +0 -28
- package/src/clear-button-mixin.js +0 -82
- package/src/delegate-input-state-mixin.d.ts +0 -43
- package/src/delegate-input-state-mixin.js +0 -63
- package/src/disabled-mixin.d.ts +0 -23
- package/src/disabled-mixin.js +0 -60
- package/src/field-aria-mixin.d.ts +0 -24
- package/src/field-aria-mixin.js +0 -61
- package/src/focus-mixin.d.ts +0 -33
- package/src/focus-mixin.js +0 -104
- package/src/helper-text-mixin.d.ts +0 -24
- package/src/helper-text-mixin.js +0 -144
- package/src/input-slot-mixin.d.ts +0 -26
- package/src/input-slot-mixin.js +0 -71
- package/src/keyboard-mixin.d.ts +0 -32
- package/src/keyboard-mixin.js +0 -51
- package/src/slot-mixin.d.ts +0 -23
- package/src/slot-mixin.js +0 -49
- package/src/tabindex-mixin.d.ts +0 -29
- package/src/tabindex-mixin.js +0 -78
- package/src/text-area-slot-mixin.d.ts +0 -21
- package/src/text-area-slot-mixin.js +0 -56
- package/src/text-field-mixin.d.ts +0 -21
- package/src/text-field-mixin.js +0 -17
package/src/input-field-mixin.js
CHANGED
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class InputFieldMixinClass extends ClearButtonMixin(
|
|
17
|
-
FieldAriaMixin(InputConstraintsMixin(AriaLabelMixin(DelegateFocusMixin(superclass))))
|
|
18
|
-
) {
|
|
6
|
+
import { InputControlMixin } from './input-control-mixin.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A mixin to provide logic for vaadin-text-field and related components.
|
|
10
|
+
*
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
* @mixes InputControlMixin
|
|
13
|
+
*/
|
|
14
|
+
export const InputFieldMixin = (superclass) =>
|
|
15
|
+
class InputFieldMixinClass extends InputControlMixin(superclass) {
|
|
19
16
|
static get properties() {
|
|
20
17
|
return {
|
|
21
18
|
/**
|
|
@@ -52,11 +49,19 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
52
49
|
},
|
|
53
50
|
|
|
54
51
|
/**
|
|
55
|
-
*
|
|
52
|
+
* A pattern matched against individual characters the user inputs.
|
|
53
|
+
* When set, the field will prevent:
|
|
54
|
+
* - `keyDown` events if the entered key doesn't match `/^_enabledCharPattern$/`
|
|
55
|
+
* - `paste` events if the pasted text doesn't match `/^_enabledCharPattern*$/`
|
|
56
|
+
* - `drop` events if the dropped text doesn't match `/^_enabledCharPattern*$/`
|
|
57
|
+
*
|
|
58
|
+
* For example, to enable entering only numbers and minus signs,
|
|
59
|
+
* `_enabledCharPattern = "[\\d-]"`
|
|
60
|
+
* @protected
|
|
56
61
|
*/
|
|
57
|
-
|
|
58
|
-
type:
|
|
59
|
-
|
|
62
|
+
_enabledCharPattern: {
|
|
63
|
+
type: String,
|
|
64
|
+
observer: '_enabledCharPatternChanged'
|
|
60
65
|
}
|
|
61
66
|
};
|
|
62
67
|
}
|
|
@@ -65,40 +70,31 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
65
70
|
return [...super.delegateAttrs, 'autocapitalize', 'autocomplete', 'autocorrect'];
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
constructor() {
|
|
74
|
+
super();
|
|
75
|
+
|
|
76
|
+
this._boundOnPaste = this._onPaste.bind(this);
|
|
77
|
+
this._boundOnDrop = this._onDrop.bind(this);
|
|
78
|
+
this._boundOnBeforeInput = this._onBeforeInput.bind(this);
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
/**
|
|
73
|
-
*
|
|
82
|
+
* @param {HTMLElement} input
|
|
74
83
|
* @protected
|
|
84
|
+
* @override
|
|
75
85
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** @protected */
|
|
81
|
-
ready() {
|
|
82
|
-
super.ready();
|
|
83
|
-
|
|
84
|
-
// Lumo theme defines a max-height transition for the "error-message"
|
|
85
|
-
// part on invalid state change.
|
|
86
|
-
const errorPart = this.shadowRoot.querySelector('[part="error-message"]');
|
|
87
|
-
if (errorPart) {
|
|
88
|
-
errorPart.addEventListener('transitionend', () => {
|
|
89
|
-
this.__observeOffsetHeight();
|
|
90
|
-
});
|
|
91
|
-
}
|
|
86
|
+
_inputElementChanged(input) {
|
|
87
|
+
super._inputElementChanged(input);
|
|
92
88
|
|
|
93
|
-
if (
|
|
89
|
+
if (input) {
|
|
94
90
|
// Discard value set on the custom slotted input.
|
|
95
|
-
if (
|
|
91
|
+
if (input.value && input.value !== this.value) {
|
|
96
92
|
console.warn(`Please define value on the <${this.localName}> component!`);
|
|
97
|
-
|
|
93
|
+
input.value = '';
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
if (this.value) {
|
|
101
|
-
|
|
97
|
+
input.value = this.value;
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
}
|
|
@@ -113,73 +109,122 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
113
109
|
}
|
|
114
110
|
|
|
115
111
|
/**
|
|
116
|
-
* Override an event listener from `
|
|
112
|
+
* Override an event listener from `DelegateFocusMixin`.
|
|
117
113
|
* @param {FocusEvent} event
|
|
118
114
|
* @protected
|
|
119
115
|
* @override
|
|
120
116
|
*/
|
|
121
|
-
|
|
122
|
-
super.
|
|
117
|
+
_onBlur(event) {
|
|
118
|
+
super._onBlur(event);
|
|
123
119
|
|
|
124
|
-
|
|
125
|
-
this.inputElement.select();
|
|
126
|
-
}
|
|
120
|
+
this.validate();
|
|
127
121
|
}
|
|
128
122
|
|
|
129
123
|
/**
|
|
130
|
-
* Override
|
|
131
|
-
*
|
|
124
|
+
* Override a method from `InputMixin` to validate the field
|
|
125
|
+
* when a new value is set programmatically.
|
|
126
|
+
* @param {string} value
|
|
132
127
|
* @protected
|
|
133
128
|
* @override
|
|
134
129
|
*/
|
|
135
|
-
|
|
136
|
-
super.
|
|
130
|
+
_forwardInputValue(value) {
|
|
131
|
+
super._forwardInputValue(value);
|
|
137
132
|
|
|
138
|
-
this.
|
|
133
|
+
if (this.invalid) {
|
|
134
|
+
this.validate();
|
|
135
|
+
}
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
139
|
+
* Override a method from `InputMixin`.
|
|
140
|
+
* @param {!HTMLElement} input
|
|
144
141
|
* @protected
|
|
142
|
+
* @override
|
|
145
143
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (this[oldSize] !== undefined && this[oldSize] !== value) {
|
|
149
|
-
this.dispatchEvent(new CustomEvent('iron-resize', { bubbles: true, composed: true }));
|
|
150
|
-
}
|
|
144
|
+
_addInputListeners(input) {
|
|
145
|
+
super._addInputListeners(input);
|
|
151
146
|
|
|
152
|
-
this
|
|
147
|
+
input.addEventListener('paste', this._boundOnPaste);
|
|
148
|
+
input.addEventListener('drop', this._boundOnDrop);
|
|
149
|
+
input.addEventListener('beforeinput', this._boundOnBeforeInput);
|
|
153
150
|
}
|
|
154
151
|
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Override a method from `InputMixin`.
|
|
154
|
+
* @param {!HTMLElement} input
|
|
155
|
+
* @protected
|
|
156
|
+
* @override
|
|
157
|
+
*/
|
|
158
|
+
_removeInputListeners(input) {
|
|
159
|
+
super._removeInputListeners(input);
|
|
160
|
+
|
|
161
|
+
input.removeEventListener('paste', this._boundOnPaste);
|
|
162
|
+
input.removeEventListener('drop', this._boundOnDrop);
|
|
163
|
+
input.removeEventListener('beforeinput', this._boundOnBeforeInput);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
|
-
* Override
|
|
168
|
-
*
|
|
169
|
-
* @param {
|
|
167
|
+
* Override an event listener from `ClearButtonMixin`
|
|
168
|
+
* to avoid adding a separate listener.
|
|
169
|
+
* @param {!KeyboardEvent} event
|
|
170
170
|
* @protected
|
|
171
171
|
* @override
|
|
172
172
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
_onKeyDown(event) {
|
|
174
|
+
if (this._enabledCharPattern && !this.__shouldAcceptKey(event)) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
}
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
+
super._onKeyDown(event);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @private */
|
|
182
|
+
__shouldAcceptKey(event) {
|
|
183
|
+
return (
|
|
184
|
+
event.metaKey ||
|
|
185
|
+
event.ctrlKey ||
|
|
186
|
+
!event.key || // allow typing anything if event.key is not supported
|
|
187
|
+
event.key.length !== 1 || // allow "Backspace", "ArrowLeft" etc.
|
|
188
|
+
this.__enabledCharRegExp.test(event.key)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @private */
|
|
193
|
+
_onPaste(e) {
|
|
194
|
+
if (this._enabledCharPattern) {
|
|
195
|
+
const pastedText = (e.clipboardData || window.clipboardData).getData('text');
|
|
196
|
+
if (!this.__enabledTextRegExp.test(pastedText)) {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
}
|
|
178
199
|
}
|
|
179
200
|
}
|
|
180
|
-
};
|
|
181
201
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
/** @private */
|
|
203
|
+
_onDrop(e) {
|
|
204
|
+
if (this._enabledCharPattern) {
|
|
205
|
+
const draggedText = e.dataTransfer.getData('text');
|
|
206
|
+
if (!this.__enabledTextRegExp.test(draggedText)) {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** @private */
|
|
213
|
+
_onBeforeInput(e) {
|
|
214
|
+
// The `beforeinput` event covers all the cases for `_enabledCharPattern`: keyboard, pasting and dropping,
|
|
215
|
+
// but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
|
|
216
|
+
// because it seems to be the only way to detect and prevent specific keys on mobile devices.
|
|
217
|
+
// See https://github.com/vaadin/vaadin-text-field/issues/429
|
|
218
|
+
if (this._enabledCharPattern && e.data && !this.__enabledTextRegExp.test(e.data)) {
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** @private */
|
|
224
|
+
_enabledCharPatternChanged(charPattern) {
|
|
225
|
+
if (charPattern) {
|
|
226
|
+
this.__enabledCharRegExp = new RegExp('^' + charPattern + '$');
|
|
227
|
+
this.__enabledTextRegExp = new RegExp('^' + charPattern + '*$');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
package/src/input-mixin.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ interface InputMixin {
|
|
|
20
20
|
* Any component implementing this mixin is expected to provide it
|
|
21
21
|
* by using `this._setInputElement(input)` Polymer API.
|
|
22
22
|
*
|
|
23
|
-
* A typical case is using `
|
|
23
|
+
* A typical case is using `InputController` that does this automatically.
|
|
24
24
|
* However, the input element does not have to always be native <input>:
|
|
25
25
|
* as an example, <vaadin-combo-box-light> accepts other components.
|
|
26
26
|
*/
|
package/src/input-mixin.js
CHANGED
|
@@ -5,165 +5,176 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
40
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A mixin to store the reference to an input element
|
|
10
|
+
* and add input and change event listeners to it.
|
|
11
|
+
*
|
|
12
|
+
* @polymerMixin
|
|
13
|
+
*/
|
|
14
|
+
export const InputMixin = dedupingMixin(
|
|
15
|
+
(superclass) =>
|
|
16
|
+
class InputMixinClass extends superclass {
|
|
17
|
+
static get properties() {
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* A reference to the input element controlled by the mixin.
|
|
21
|
+
* Any component implementing this mixin is expected to provide it
|
|
22
|
+
* by using `this._setInputElement(input)` Polymer API.
|
|
23
|
+
*
|
|
24
|
+
* A typical case is using `InputController` that does this automatically.
|
|
25
|
+
* However, the input element does not have to always be native <input>:
|
|
26
|
+
* as an example, <vaadin-combo-box-light> accepts other components.
|
|
27
|
+
*
|
|
28
|
+
* @protected
|
|
29
|
+
* @type {!HTMLElement}
|
|
30
|
+
*/
|
|
31
|
+
inputElement: {
|
|
32
|
+
type: Object,
|
|
33
|
+
readOnly: true,
|
|
34
|
+
observer: '_inputElementChanged'
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* String used to define input type.
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
type: {
|
|
42
|
+
type: String,
|
|
43
|
+
readOnly: true
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The value of the field.
|
|
48
|
+
*/
|
|
49
|
+
value: {
|
|
50
|
+
type: String,
|
|
51
|
+
value: '',
|
|
52
|
+
observer: '_valueChanged',
|
|
53
|
+
notify: true
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
41
57
|
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
constructor() {
|
|
59
|
+
super();
|
|
44
60
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
this._boundOnInput = this._onInput.bind(this);
|
|
62
|
+
this._boundOnChange = this._onChange.bind(this);
|
|
63
|
+
}
|
|
48
64
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Clear the value of the field.
|
|
67
|
+
*/
|
|
68
|
+
clear() {
|
|
69
|
+
this.value = '';
|
|
70
|
+
}
|
|
55
71
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Add event listeners to the input element instance.
|
|
74
|
+
* Override this method to add custom listeners.
|
|
75
|
+
* @param {!HTMLElement} input
|
|
76
|
+
*/
|
|
77
|
+
_addInputListeners(input) {
|
|
78
|
+
input.addEventListener('input', this._boundOnInput);
|
|
79
|
+
input.addEventListener('change', this._boundOnChange);
|
|
80
|
+
}
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Remove event listeners from the input element instance.
|
|
84
|
+
* @param {!HTMLElement} input
|
|
85
|
+
*/
|
|
86
|
+
_removeInputListeners(input) {
|
|
87
|
+
input.removeEventListener('input', this._boundOnInput);
|
|
88
|
+
input.removeEventListener('change', this._boundOnChange);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A method to forward the value property set on the field
|
|
93
|
+
* programmatically back to the input element value.
|
|
94
|
+
* Override this method to perform additional checks,
|
|
95
|
+
* for example to skip this in certain conditions.
|
|
96
|
+
* @param {string} value
|
|
97
|
+
* @protected
|
|
98
|
+
* @override
|
|
99
|
+
*/
|
|
100
|
+
_forwardInputValue(value) {
|
|
101
|
+
// Value might be set before an input element is initialized.
|
|
102
|
+
// This case should be handled separately by a component that
|
|
103
|
+
// implements this mixin, for example in `connectedCallback`.
|
|
104
|
+
if (!this.inputElement) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
74
107
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* @param {string} value
|
|
81
|
-
* @protected
|
|
82
|
-
* @override
|
|
83
|
-
*/
|
|
84
|
-
_forwardInputValue(value) {
|
|
85
|
-
// Value might be set before an input element is initialized.
|
|
86
|
-
// This case should be handled separately by a component that
|
|
87
|
-
// implements this mixin, for example in `connectedCallback`.
|
|
88
|
-
if (!this.inputElement) {
|
|
89
|
-
return;
|
|
108
|
+
if (value != undefined) {
|
|
109
|
+
this.inputElement.value = value;
|
|
110
|
+
} else {
|
|
111
|
+
this.inputElement.value = '';
|
|
112
|
+
}
|
|
90
113
|
}
|
|
91
114
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
/** @protected */
|
|
116
|
+
_inputElementChanged(input, oldInput) {
|
|
117
|
+
if (input) {
|
|
118
|
+
this._addInputListeners(input);
|
|
119
|
+
} else if (oldInput) {
|
|
120
|
+
this._removeInputListeners(oldInput);
|
|
121
|
+
}
|
|
96
122
|
}
|
|
97
|
-
}
|
|
98
123
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
124
|
+
/**
|
|
125
|
+
* An input event listener used to update the field value.
|
|
126
|
+
* Override this method with an actual implementation.
|
|
127
|
+
* @param {Event} _event
|
|
128
|
+
* @protected
|
|
129
|
+
* @override
|
|
130
|
+
*/
|
|
131
|
+
_onInput(event) {
|
|
132
|
+
// Ignore fake input events e.g. used by clear button.
|
|
133
|
+
this.__userInput = event.isTrusted;
|
|
134
|
+
this.value = event.target.value;
|
|
135
|
+
this.__userInput = false;
|
|
105
136
|
}
|
|
106
|
-
}
|
|
107
137
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
138
|
+
/**
|
|
139
|
+
* A change event listener.
|
|
140
|
+
* Override this method with an actual implementation.
|
|
141
|
+
* @param {Event} _event
|
|
142
|
+
* @protected
|
|
143
|
+
* @override
|
|
144
|
+
*/
|
|
145
|
+
_onChange(_event) {}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Toggle the has-value attribute based on the value property.
|
|
149
|
+
* @param {boolean} hasValue
|
|
150
|
+
* @protected
|
|
151
|
+
*/
|
|
152
|
+
_toggleHasValue(hasValue) {
|
|
153
|
+
this.toggleAttribute('has-value', hasValue);
|
|
154
|
+
}
|
|
121
155
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
_toggleHasValue(hasValue) {
|
|
137
|
-
this.toggleAttribute('has-value', hasValue);
|
|
138
|
-
}
|
|
156
|
+
/**
|
|
157
|
+
* Observer called when a value property changes.
|
|
158
|
+
* @param {string | undefined} newVal
|
|
159
|
+
* @param {string | undefined} oldVal
|
|
160
|
+
* @protected
|
|
161
|
+
* @override
|
|
162
|
+
*/
|
|
163
|
+
_valueChanged(newVal, oldVal) {
|
|
164
|
+
this._toggleHasValue(newVal !== '' && newVal != null);
|
|
165
|
+
|
|
166
|
+
// Setting initial value to empty string, do nothing.
|
|
167
|
+
if (newVal === '' && oldVal === undefined) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
139
170
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
* @protected
|
|
145
|
-
* @override
|
|
146
|
-
*/
|
|
147
|
-
_valueChanged(newVal, oldVal) {
|
|
148
|
-
this._toggleHasValue(newVal !== '' && newVal != null);
|
|
149
|
-
|
|
150
|
-
// Setting initial value to empty string, do nothing.
|
|
151
|
-
if (newVal === '' && oldVal === undefined) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
171
|
+
// Value is set by the user, no need to sync it back to input.
|
|
172
|
+
if (this.__userInput) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
154
175
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return;
|
|
176
|
+
// Setting a value programmatically, sync it to input element.
|
|
177
|
+
this._forwardInputValue(newVal);
|
|
158
178
|
}
|
|
159
|
-
|
|
160
|
-
// Setting a value programmatically, sync it to input element.
|
|
161
|
-
this._forwardInputValue(newVal);
|
|
162
179
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* A mixin to store the reference to an input element
|
|
167
|
-
* and add input and change event listeners to it.
|
|
168
|
-
*/
|
|
169
|
-
export const InputMixin = dedupingMixin(InputMixinImplementation);
|
|
180
|
+
);
|
package/src/label-mixin.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { SlotMixin } from '
|
|
6
|
+
import { SlotMixin } from '@vaadin/component-base/src/slot-mixin.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A mixin to provide label via corresponding property or named slot.
|
|
@@ -18,7 +18,7 @@ interface LabelMixin extends SlotMixin {
|
|
|
18
18
|
/**
|
|
19
19
|
* String used for a label element.
|
|
20
20
|
*/
|
|
21
|
-
label: string;
|
|
21
|
+
label: string | null | undefined;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export { LabelMixinConstructor, LabelMixin };
|