@vaadin/vaadin-text-field 22.0.0-alpha4 → 22.0.0-alpha8
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 +28 -33
- package/src/vaadin-email-field.d.ts +12 -0
- package/src/vaadin-email-field.js +7 -0
- package/src/vaadin-integer-field.d.ts +12 -0
- package/src/vaadin-integer-field.js +7 -0
- package/src/vaadin-number-field.d.ts +12 -0
- package/src/vaadin-number-field.js +7 -0
- package/src/vaadin-password-field.d.ts +12 -0
- package/src/vaadin-password-field.js +7 -0
- package/src/vaadin-text-area.d.ts +12 -0
- package/src/vaadin-text-area.js +7 -0
- package/src/vaadin-text-field.d.ts +13 -98
- package/src/vaadin-text-field.js +4 -131
- package/theme/lumo/vaadin-text-field.js +6 -2
- package/theme/material/vaadin-text-field.js +6 -2
- package/vaadin-text-field.d.ts +0 -1
- package/src/interfaces.d.ts +0 -21
- package/src/vaadin-text-field-mixin.d.ts +0 -174
- package/src/vaadin-text-field-mixin.js +0 -874
- package/theme/lumo/vaadin-text-field-styles.js +0 -354
- package/theme/material/vaadin-text-field-styles.js +0 -220
|
@@ -1,874 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
|
|
7
|
-
import { timeOut, animationFrame } from '@polymer/polymer/lib/utils/async.js';
|
|
8
|
-
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
9
|
-
|
|
10
|
-
registerStyles(
|
|
11
|
-
'',
|
|
12
|
-
css`
|
|
13
|
-
:host {
|
|
14
|
-
display: inline-flex;
|
|
15
|
-
outline: none;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
:host::before {
|
|
19
|
-
content: '\\2003';
|
|
20
|
-
width: 0;
|
|
21
|
-
display: inline-block;
|
|
22
|
-
/* Size and position this element on the same vertical position as the input-field element
|
|
23
|
-
to make vertical align for the host element work as expected */
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
:host([hidden]) {
|
|
27
|
-
display: none !important;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.vaadin-text-field-container {
|
|
31
|
-
display: flex;
|
|
32
|
-
flex-direction: column;
|
|
33
|
-
min-width: 100%;
|
|
34
|
-
max-width: 100%;
|
|
35
|
-
width: var(--vaadin-text-field-default-width, 12em);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
[part='label']:empty {
|
|
39
|
-
display: none;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
[part='input-field'] {
|
|
43
|
-
display: flex;
|
|
44
|
-
align-items: center;
|
|
45
|
-
flex: auto;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.vaadin-text-field-container [part='input-field'] {
|
|
49
|
-
flex-grow: 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/* Reset the native input styles */
|
|
53
|
-
[part='value'],
|
|
54
|
-
[part='input-field'] ::slotted(input),
|
|
55
|
-
[part='input-field'] ::slotted(textarea) {
|
|
56
|
-
-webkit-appearance: none;
|
|
57
|
-
-moz-appearance: none;
|
|
58
|
-
outline: none;
|
|
59
|
-
margin: 0;
|
|
60
|
-
padding: 0;
|
|
61
|
-
border: 0;
|
|
62
|
-
border-radius: 0;
|
|
63
|
-
min-width: 0;
|
|
64
|
-
font: inherit;
|
|
65
|
-
font-size: 1em;
|
|
66
|
-
line-height: normal;
|
|
67
|
-
color: inherit;
|
|
68
|
-
background-color: transparent;
|
|
69
|
-
/* Disable default invalid style in Firefox */
|
|
70
|
-
box-shadow: none;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
[part='input-field'] ::slotted(*) {
|
|
74
|
-
flex: none;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
[part='value'],
|
|
78
|
-
[part='input-field'] ::slotted(input),
|
|
79
|
-
[part='input-field'] ::slotted(textarea),
|
|
80
|
-
[part='input-field'] ::slotted([part='value']) {
|
|
81
|
-
flex: auto;
|
|
82
|
-
white-space: nowrap;
|
|
83
|
-
overflow: hidden;
|
|
84
|
-
width: 100%;
|
|
85
|
-
height: 100%;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
[part='input-field'] ::slotted(textarea) {
|
|
89
|
-
resize: none;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
[part='clear-button'] {
|
|
93
|
-
display: none;
|
|
94
|
-
cursor: default;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
[part='clear-button']::before {
|
|
98
|
-
content: '✕';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
:host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
|
|
102
|
-
display: block;
|
|
103
|
-
}
|
|
104
|
-
`,
|
|
105
|
-
{ moduleId: 'vaadin-text-field-shared-styles' }
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const HOST_PROPS = {
|
|
109
|
-
default: [
|
|
110
|
-
'autofocus',
|
|
111
|
-
'pattern',
|
|
112
|
-
'autocapitalize',
|
|
113
|
-
'autocorrect',
|
|
114
|
-
'maxlength',
|
|
115
|
-
'minlength',
|
|
116
|
-
'name',
|
|
117
|
-
'placeholder',
|
|
118
|
-
'autocomplete',
|
|
119
|
-
'title',
|
|
120
|
-
'disabled',
|
|
121
|
-
'readonly',
|
|
122
|
-
'required'
|
|
123
|
-
],
|
|
124
|
-
accessible: ['invalid']
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const PROP_TYPE = {
|
|
128
|
-
DEFAULT: 'default',
|
|
129
|
-
ACCESSIBLE: 'accessible'
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @polymerMixin
|
|
134
|
-
*/
|
|
135
|
-
export const TextFieldMixin = (subclass) =>
|
|
136
|
-
class VaadinTextFieldMixin extends subclass {
|
|
137
|
-
static get properties() {
|
|
138
|
-
return {
|
|
139
|
-
/**
|
|
140
|
-
* Whether the value of the control can be automatically completed by the browser.
|
|
141
|
-
* List of available options at:
|
|
142
|
-
* https://developer.mozilla.org/en/docs/Web/HTML/Element/input#attr-autocomplete
|
|
143
|
-
*/
|
|
144
|
-
autocomplete: {
|
|
145
|
-
type: String
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* This is a property supported by Safari that is used to control whether
|
|
150
|
-
* autocorrection should be enabled when the user is entering/editing the text.
|
|
151
|
-
* Possible values are:
|
|
152
|
-
* on: Enable autocorrection.
|
|
153
|
-
* off: Disable autocorrection.
|
|
154
|
-
* @type {!TextFieldAutoCorrect | undefined}
|
|
155
|
-
*/
|
|
156
|
-
autocorrect: {
|
|
157
|
-
type: String
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* This is a property supported by Safari and Chrome that is used to control whether
|
|
162
|
-
* autocapitalization should be enabled when the user is entering/editing the text.
|
|
163
|
-
* Possible values are:
|
|
164
|
-
* characters: Characters capitalization.
|
|
165
|
-
* words: Words capitalization.
|
|
166
|
-
* sentences: Sentences capitalization.
|
|
167
|
-
* none: No capitalization.
|
|
168
|
-
* @type {!TextFieldAutoCapitalize | undefined}
|
|
169
|
-
*/
|
|
170
|
-
autocapitalize: {
|
|
171
|
-
type: String
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Specify that the value should be automatically selected when the field gains focus.
|
|
176
|
-
* @type {boolean}
|
|
177
|
-
*/
|
|
178
|
-
autoselect: {
|
|
179
|
-
type: Boolean,
|
|
180
|
-
value: false
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Set to true to display the clear icon which clears the input.
|
|
185
|
-
* @attr {boolean} clear-button-visible
|
|
186
|
-
* @type {boolean}
|
|
187
|
-
*/
|
|
188
|
-
clearButtonVisible: {
|
|
189
|
-
type: Boolean,
|
|
190
|
-
value: false,
|
|
191
|
-
reflectToAttribute: true
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Error to show when the input value is invalid.
|
|
196
|
-
* @attr {string} error-message
|
|
197
|
-
* @type {string}
|
|
198
|
-
*/
|
|
199
|
-
errorMessage: {
|
|
200
|
-
type: String,
|
|
201
|
-
value: '',
|
|
202
|
-
observer: '_errorMessageChanged'
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Object with translated strings used for localization. Has
|
|
207
|
-
* the following structure and default values:
|
|
208
|
-
*
|
|
209
|
-
* ```
|
|
210
|
-
* {
|
|
211
|
-
* // Translation of the clear icon button accessible label
|
|
212
|
-
* clear: 'Clear'
|
|
213
|
-
* }
|
|
214
|
-
* ```
|
|
215
|
-
* @type {{clear: string}}
|
|
216
|
-
*/
|
|
217
|
-
i18n: {
|
|
218
|
-
type: Object,
|
|
219
|
-
value: () => {
|
|
220
|
-
return {
|
|
221
|
-
clear: 'Clear'
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* String used for the label element.
|
|
228
|
-
* @type {string}
|
|
229
|
-
*/
|
|
230
|
-
label: {
|
|
231
|
-
type: String,
|
|
232
|
-
value: '',
|
|
233
|
-
observer: '_labelChanged'
|
|
234
|
-
},
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* String used for the helper text.
|
|
238
|
-
* @attr {string} helper-text
|
|
239
|
-
* @type {string | null}
|
|
240
|
-
*/
|
|
241
|
-
helperText: {
|
|
242
|
-
type: String,
|
|
243
|
-
value: '',
|
|
244
|
-
observer: '_helperTextChanged'
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Maximum number of characters (in Unicode code points) that the user can enter.
|
|
249
|
-
*/
|
|
250
|
-
maxlength: {
|
|
251
|
-
type: Number
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Minimum number of characters (in Unicode code points) that the user can enter.
|
|
256
|
-
*/
|
|
257
|
-
minlength: {
|
|
258
|
-
type: Number
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* The name of the control, which is submitted with the form data.
|
|
263
|
-
*/
|
|
264
|
-
name: {
|
|
265
|
-
type: String
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* A hint to the user of what can be entered in the control.
|
|
270
|
-
*/
|
|
271
|
-
placeholder: {
|
|
272
|
-
type: String
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* This attribute indicates that the user cannot modify the value of the control.
|
|
277
|
-
*/
|
|
278
|
-
readonly: {
|
|
279
|
-
type: Boolean,
|
|
280
|
-
reflectToAttribute: true
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Specifies that the user must fill in a value.
|
|
285
|
-
*/
|
|
286
|
-
required: {
|
|
287
|
-
type: Boolean,
|
|
288
|
-
reflectToAttribute: true
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* The initial value of the control.
|
|
293
|
-
* It can be used for two-way data binding.
|
|
294
|
-
* @type {string}
|
|
295
|
-
*/
|
|
296
|
-
value: {
|
|
297
|
-
type: String,
|
|
298
|
-
value: '',
|
|
299
|
-
observer: '_valueChanged',
|
|
300
|
-
notify: true
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* This property is set to true when the control value is invalid.
|
|
305
|
-
* @type {boolean}
|
|
306
|
-
*/
|
|
307
|
-
invalid: {
|
|
308
|
-
type: Boolean,
|
|
309
|
-
reflectToAttribute: true,
|
|
310
|
-
notify: true,
|
|
311
|
-
value: false
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* When set to true, user is prevented from typing a value that
|
|
316
|
-
* conflicts with the given `pattern`.
|
|
317
|
-
* @attr {boolean} prevent-invalid-input
|
|
318
|
-
*/
|
|
319
|
-
preventInvalidInput: {
|
|
320
|
-
type: Boolean
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* A pattern matched against individual characters the user inputs.
|
|
325
|
-
* When set, the field will prevent:
|
|
326
|
-
* - `keyDown` events if the entered key doesn't match `/^_enabledCharPattern$/`
|
|
327
|
-
* - `paste` events if the pasted text doesn't match `/^_enabledCharPattern*$/`
|
|
328
|
-
* - `drop` events if the dropped text doesn't match `/^_enabledCharPattern*$/`
|
|
329
|
-
*
|
|
330
|
-
* For example, to enable entering only numbers and minus signs,
|
|
331
|
-
* `_enabledCharPattern = "[\\d-]"`
|
|
332
|
-
* @protected
|
|
333
|
-
*/
|
|
334
|
-
_enabledCharPattern: String,
|
|
335
|
-
|
|
336
|
-
/** @private */
|
|
337
|
-
_labelId: String,
|
|
338
|
-
|
|
339
|
-
/** @private */
|
|
340
|
-
_helperTextId: String,
|
|
341
|
-
|
|
342
|
-
/** @private */
|
|
343
|
-
_errorId: String,
|
|
344
|
-
|
|
345
|
-
/** @private */
|
|
346
|
-
_inputId: String,
|
|
347
|
-
|
|
348
|
-
/** @private */
|
|
349
|
-
_hasSlottedHelper: Boolean
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
static get observers() {
|
|
354
|
-
return [
|
|
355
|
-
'_hostPropsChanged(' + HOST_PROPS.default.join(', ') + ')',
|
|
356
|
-
'_hostAccessiblePropsChanged(' + HOST_PROPS.accessible.join(', ') + ')',
|
|
357
|
-
'_getActiveErrorId(invalid, errorMessage, _errorId, helperText, _helperTextId, _hasSlottedHelper)',
|
|
358
|
-
'_getActiveLabelId(label, _labelId, _inputId)',
|
|
359
|
-
'__observeOffsetHeight(errorMessage, invalid, label, helperText)',
|
|
360
|
-
'__enabledCharPatternChanged(_enabledCharPattern)'
|
|
361
|
-
];
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* @return {HTMLElement | undefined}
|
|
366
|
-
* @protected
|
|
367
|
-
*/
|
|
368
|
-
get focusElement() {
|
|
369
|
-
if (!this.shadowRoot) {
|
|
370
|
-
return undefined;
|
|
371
|
-
}
|
|
372
|
-
const slotted = this.querySelector(`${this._slottedTagName}[slot="${this._slottedTagName}"]`);
|
|
373
|
-
if (slotted) {
|
|
374
|
-
return slotted;
|
|
375
|
-
}
|
|
376
|
-
return this.shadowRoot.querySelector('[part="value"]');
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* @return {HTMLElement | undefined}}
|
|
381
|
-
* @protected
|
|
382
|
-
*/
|
|
383
|
-
get inputElement() {
|
|
384
|
-
return this.focusElement;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* @return {string}
|
|
389
|
-
* @protected
|
|
390
|
-
*/
|
|
391
|
-
get _slottedTagName() {
|
|
392
|
-
return 'input';
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/** @protected */
|
|
396
|
-
_createConstraintsObserver() {
|
|
397
|
-
// This complex observer needs to be added dynamically here (instead of defining it above in the `get observers()`)
|
|
398
|
-
// so that it runs after complex observers of inheriting classes. Otherwise e.g. `_stepOrMinChanged()` observer of
|
|
399
|
-
// vaadin-number-field would run after this and the `min` and `step` properties would not yet be propagated to
|
|
400
|
-
// the `inputElement` when this runs.
|
|
401
|
-
this._createMethodObserver('_constraintsChanged(required, minlength, maxlength, pattern)');
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/** @private */
|
|
405
|
-
_onInput(e) {
|
|
406
|
-
if (this.preventInvalidInput) {
|
|
407
|
-
const input = this.inputElement;
|
|
408
|
-
if (input.value.length > 0 && !this.checkValidity()) {
|
|
409
|
-
input.value = this.value || '';
|
|
410
|
-
// add input-prevented attribute for 200ms
|
|
411
|
-
this.setAttribute('input-prevented', '');
|
|
412
|
-
this._inputDebouncer = Debouncer.debounce(this._inputDebouncer, timeOut.after(200), () => {
|
|
413
|
-
this.removeAttribute('input-prevented');
|
|
414
|
-
});
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (!e.__fromClearButton) {
|
|
420
|
-
this.__userInput = true;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
this.value = e.target.value;
|
|
424
|
-
this.__userInput = false;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* @param {!Event} e
|
|
429
|
-
* @protected
|
|
430
|
-
*/
|
|
431
|
-
_onChange(e) {
|
|
432
|
-
if (this._valueClearing) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// In the Shadow DOM, the `change` event is not leaked into the
|
|
437
|
-
// ancestor tree, so we must do this manually.
|
|
438
|
-
const changeEvent = new CustomEvent('change', {
|
|
439
|
-
detail: {
|
|
440
|
-
sourceEvent: e
|
|
441
|
-
},
|
|
442
|
-
bubbles: e.bubbles,
|
|
443
|
-
cancelable: e.cancelable
|
|
444
|
-
});
|
|
445
|
-
this.dispatchEvent(changeEvent);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* @param {unknown} newVal
|
|
450
|
-
* @param {unknown} oldVal
|
|
451
|
-
* @protected
|
|
452
|
-
*/
|
|
453
|
-
_valueChanged(newVal, oldVal) {
|
|
454
|
-
// setting initial value to empty string, skip validation
|
|
455
|
-
if (newVal === '' && oldVal === undefined) {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (newVal !== '' && newVal != null) {
|
|
460
|
-
this.setAttribute('has-value', '');
|
|
461
|
-
} else {
|
|
462
|
-
this.removeAttribute('has-value');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (this.__userInput) {
|
|
466
|
-
return;
|
|
467
|
-
} else if (newVal !== undefined) {
|
|
468
|
-
this.inputElement.value = newVal;
|
|
469
|
-
} else {
|
|
470
|
-
this.value = this.inputElement.value = '';
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (this.invalid) {
|
|
474
|
-
this.validate();
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/** @private */
|
|
479
|
-
_labelChanged(label) {
|
|
480
|
-
this._setOrToggleAttribute('has-label', !!label, this);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/** @private */
|
|
484
|
-
_helperTextChanged(helperText) {
|
|
485
|
-
this._setOrToggleAttribute('has-helper', !!helperText, this);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/** @private */
|
|
489
|
-
_errorMessageChanged(errorMessage) {
|
|
490
|
-
this._setOrToggleAttribute('has-error-message', !!errorMessage, this);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/** @private */
|
|
494
|
-
_onHelperSlotChange() {
|
|
495
|
-
const slottedNodes = this.shadowRoot.querySelector(`[name="helper"]`).assignedNodes({ flatten: true });
|
|
496
|
-
// Only has slotted helper if not a text node
|
|
497
|
-
// Text nodes are added by the helperText prop and not the helper slot
|
|
498
|
-
// The filter is added due to shady DOM triggering this callback on helperText prop change
|
|
499
|
-
this._hasSlottedHelper = slottedNodes.filter((node) => node.nodeType !== 3).length;
|
|
500
|
-
|
|
501
|
-
if (this._hasSlottedHelper) {
|
|
502
|
-
this.setAttribute('has-helper', 'slotted');
|
|
503
|
-
} else if (this.helperText === '' || this.helperText === null) {
|
|
504
|
-
this.removeAttribute('has-helper');
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/** @private */
|
|
509
|
-
_onSlotChange() {
|
|
510
|
-
const slotted = this.querySelector(`${this._slottedTagName}[slot="${this._slottedTagName}"]`);
|
|
511
|
-
|
|
512
|
-
if (this.value) {
|
|
513
|
-
this.inputElement.value = this.value;
|
|
514
|
-
this.validate();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (slotted && !this._slottedInput) {
|
|
518
|
-
this._validateSlottedValue(slotted);
|
|
519
|
-
this._addInputListeners(slotted);
|
|
520
|
-
this._slottedInput = slotted;
|
|
521
|
-
} else if (!slotted && this._slottedInput) {
|
|
522
|
-
this._removeInputListeners(this._slottedInput);
|
|
523
|
-
this._slottedInput = undefined;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
Object.keys(PROP_TYPE)
|
|
527
|
-
.map((key) => PROP_TYPE[key])
|
|
528
|
-
.forEach((type) =>
|
|
529
|
-
this._propagateHostAttributes(
|
|
530
|
-
HOST_PROPS[type].map((attr) => this[attr]),
|
|
531
|
-
type
|
|
532
|
-
)
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/** @private */
|
|
537
|
-
_hostPropsChanged(...attributesValues) {
|
|
538
|
-
this._propagateHostAttributes(attributesValues, PROP_TYPE.DEFAULT);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
/** @private */
|
|
542
|
-
_hostAccessiblePropsChanged(...attributesValues) {
|
|
543
|
-
this._propagateHostAttributes(attributesValues, PROP_TYPE.ACCESSIBLE);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/** @private */
|
|
547
|
-
_validateSlottedValue(slotted) {
|
|
548
|
-
if (slotted.value !== this.value) {
|
|
549
|
-
console.warn('Please define value on the vaadin-text-field component!');
|
|
550
|
-
slotted.value = '';
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/** @private */
|
|
555
|
-
_propagateHostAttributes(attributesValues, type) {
|
|
556
|
-
const input = this.inputElement;
|
|
557
|
-
const attributeNames = HOST_PROPS[type];
|
|
558
|
-
|
|
559
|
-
if (type === PROP_TYPE.ACCESSIBLE) {
|
|
560
|
-
attributeNames.forEach((attr, index) => {
|
|
561
|
-
this._setOrToggleAttribute(attr, attributesValues[index], input);
|
|
562
|
-
this._setOrToggleAttribute(`aria-${attr}`, attributesValues[index] ? 'true' : false, input);
|
|
563
|
-
});
|
|
564
|
-
} else {
|
|
565
|
-
attributeNames.forEach((attr, index) => {
|
|
566
|
-
this._setOrToggleAttribute(attr, attributesValues[index], input);
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/** @private */
|
|
572
|
-
_setOrToggleAttribute(name, value, node) {
|
|
573
|
-
if (!name || !node) {
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (value) {
|
|
578
|
-
node.setAttribute(name, typeof value === 'boolean' ? '' : value);
|
|
579
|
-
} else {
|
|
580
|
-
node.removeAttribute(name);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* @param {boolean | undefined} required
|
|
586
|
-
* @param {number | undefined} minlength
|
|
587
|
-
* @param {number | undefined} maxlength
|
|
588
|
-
* @param {string | undefined} maxlength
|
|
589
|
-
* @protected
|
|
590
|
-
*/
|
|
591
|
-
_constraintsChanged(required, minlength, maxlength, pattern) {
|
|
592
|
-
if (!this.invalid) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
if (!required && !minlength && !maxlength && !pattern) {
|
|
597
|
-
this.invalid = false;
|
|
598
|
-
} else {
|
|
599
|
-
this.validate();
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Returns true if the current input value satisfies all constraints (if any)
|
|
605
|
-
* @return {boolean}
|
|
606
|
-
*/
|
|
607
|
-
checkValidity() {
|
|
608
|
-
// Note (Yuriy): `__forceCheckValidity` is used in containing components (i.e. `vaadin-date-picker`) in order
|
|
609
|
-
// to force the checkValidity instead of returning the previous invalid state.
|
|
610
|
-
if (this.required || this.pattern || this.maxlength || this.minlength || this.__forceCheckValidity) {
|
|
611
|
-
return this.inputElement.checkValidity();
|
|
612
|
-
} else {
|
|
613
|
-
return !this.invalid;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/** @private */
|
|
618
|
-
_addInputListeners(node) {
|
|
619
|
-
node.addEventListener('input', this._boundOnInput);
|
|
620
|
-
node.addEventListener('change', this._boundOnChange);
|
|
621
|
-
node.addEventListener('blur', this._boundOnBlur);
|
|
622
|
-
node.addEventListener('focus', this._boundOnFocus);
|
|
623
|
-
node.addEventListener('paste', this._boundOnPaste);
|
|
624
|
-
node.addEventListener('drop', this._boundOnDrop);
|
|
625
|
-
node.addEventListener('beforeinput', this._boundOnBeforeInput);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/** @private */
|
|
629
|
-
_removeInputListeners(node) {
|
|
630
|
-
node.removeEventListener('input', this._boundOnInput);
|
|
631
|
-
node.removeEventListener('change', this._boundOnChange);
|
|
632
|
-
node.removeEventListener('blur', this._boundOnBlur);
|
|
633
|
-
node.removeEventListener('focus', this._boundOnFocus);
|
|
634
|
-
node.removeEventListener('paste', this._boundOnPaste);
|
|
635
|
-
node.removeEventListener('drop', this._boundOnDrop);
|
|
636
|
-
node.removeEventListener('beforeinput', this._boundOnBeforeInput);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/** @protected */
|
|
640
|
-
ready() {
|
|
641
|
-
super.ready();
|
|
642
|
-
|
|
643
|
-
this._createConstraintsObserver();
|
|
644
|
-
|
|
645
|
-
this._boundOnInput = this._onInput.bind(this);
|
|
646
|
-
this._boundOnChange = this._onChange.bind(this);
|
|
647
|
-
this._boundOnBlur = this._onBlur.bind(this);
|
|
648
|
-
this._boundOnFocus = this._onFocus.bind(this);
|
|
649
|
-
this._boundOnPaste = this._onPaste.bind(this);
|
|
650
|
-
this._boundOnDrop = this._onDrop.bind(this);
|
|
651
|
-
this._boundOnBeforeInput = this._onBeforeInput.bind(this);
|
|
652
|
-
|
|
653
|
-
const defaultInput = this.shadowRoot.querySelector('[part="value"]');
|
|
654
|
-
this._slottedInput = this.querySelector(`${this._slottedTagName}[slot="${this._slottedTagName}"]`);
|
|
655
|
-
this._addInputListeners(defaultInput);
|
|
656
|
-
if (this._slottedInput) {
|
|
657
|
-
this._addInputListeners(this._slottedInput);
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
this.shadowRoot
|
|
661
|
-
.querySelector('[name="input"], [name="textarea"]')
|
|
662
|
-
.addEventListener('slotchange', this._onSlotChange.bind(this));
|
|
663
|
-
|
|
664
|
-
this._onHelperSlotChange();
|
|
665
|
-
this.shadowRoot
|
|
666
|
-
.querySelector('[name="helper"]')
|
|
667
|
-
.addEventListener('slotchange', this._onHelperSlotChange.bind(this));
|
|
668
|
-
|
|
669
|
-
this.$.clearButton.addEventListener('mousedown', () => (this._valueClearing = true));
|
|
670
|
-
this.$.clearButton.addEventListener('mouseleave', () => (this._valueClearing = false));
|
|
671
|
-
this.$.clearButton.addEventListener('click', this._onClearButtonClick.bind(this));
|
|
672
|
-
this.addEventListener('keydown', this._onKeyDown.bind(this));
|
|
673
|
-
|
|
674
|
-
var uniqueId = (TextFieldMixin._uniqueId = 1 + TextFieldMixin._uniqueId || 0);
|
|
675
|
-
this._errorId = `${this.constructor.is}-error-${uniqueId}`;
|
|
676
|
-
this._labelId = `${this.constructor.is}-label-${uniqueId}`;
|
|
677
|
-
this._helperTextId = `${this.constructor.is}-helper-${uniqueId}`;
|
|
678
|
-
this._inputId = `${this.constructor.is}-input-${uniqueId}`;
|
|
679
|
-
|
|
680
|
-
// Lumo theme defines a max-height transition for the "error-message"
|
|
681
|
-
// part on invalid state change.
|
|
682
|
-
this.shadowRoot.querySelector('[part="error-message"]').addEventListener('transitionend', () => {
|
|
683
|
-
this.__observeOffsetHeight();
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Returns true if `value` is valid.
|
|
689
|
-
*
|
|
690
|
-
* @return {boolean} True if the value is valid.
|
|
691
|
-
*/
|
|
692
|
-
validate() {
|
|
693
|
-
return !(this.invalid = !this.checkValidity());
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
clear() {
|
|
697
|
-
this.value = '';
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
/** @private */
|
|
701
|
-
_onBlur() {
|
|
702
|
-
this.validate();
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/** @private */
|
|
706
|
-
_onFocus() {
|
|
707
|
-
if (this.autoselect) {
|
|
708
|
-
this.inputElement.select();
|
|
709
|
-
// iOS 9 workaround: https://stackoverflow.com/a/7436574
|
|
710
|
-
setTimeout(() => {
|
|
711
|
-
try {
|
|
712
|
-
this.inputElement.setSelectionRange(0, 9999);
|
|
713
|
-
} catch (e) {
|
|
714
|
-
// The workaround may cause errors on different input types.
|
|
715
|
-
// Needs to be suppressed. See https://github.com/vaadin/flow/issues/6070
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/** @private */
|
|
722
|
-
_onClearButtonClick(e) {
|
|
723
|
-
e.preventDefault();
|
|
724
|
-
// NOTE(yuriy): This line won't affect focus on the host. Cannot be properly tested.
|
|
725
|
-
this.inputElement.focus();
|
|
726
|
-
this.clear();
|
|
727
|
-
this._valueClearing = false;
|
|
728
|
-
const inputEvent = new Event('input', { bubbles: true, composed: true });
|
|
729
|
-
inputEvent.__fromClearButton = true;
|
|
730
|
-
const changeEvent = new Event('change', { bubbles: !this._slottedInput });
|
|
731
|
-
changeEvent.__fromClearButton = true;
|
|
732
|
-
this.inputElement.dispatchEvent(inputEvent);
|
|
733
|
-
this.inputElement.dispatchEvent(changeEvent);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* @param {!KeyboardEvent} e
|
|
738
|
-
* @protected
|
|
739
|
-
*/
|
|
740
|
-
_onKeyDown(e) {
|
|
741
|
-
if (e.keyCode === 27 && this.clearButtonVisible) {
|
|
742
|
-
const dispatchChange = !!this.value;
|
|
743
|
-
this.clear();
|
|
744
|
-
dispatchChange && this.inputElement.dispatchEvent(new Event('change', { bubbles: !this._slottedInput }));
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
if (this._enabledCharPattern && !this.__shouldAcceptKey(e)) {
|
|
748
|
-
e.preventDefault();
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
/** @private */
|
|
753
|
-
__shouldAcceptKey(event) {
|
|
754
|
-
return (
|
|
755
|
-
event.metaKey ||
|
|
756
|
-
event.ctrlKey ||
|
|
757
|
-
!event.key || // allow typing anything if event.key is not supported
|
|
758
|
-
event.key.length !== 1 || // allow "Backspace", "ArrowLeft" etc.
|
|
759
|
-
this.__enabledCharRegExp.test(event.key)
|
|
760
|
-
);
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
/** @private */
|
|
764
|
-
_onPaste(e) {
|
|
765
|
-
if (this._enabledCharPattern) {
|
|
766
|
-
const pastedText = (e.clipboardData || window.clipboardData).getData('text');
|
|
767
|
-
if (!this.__enabledTextRegExp.test(pastedText)) {
|
|
768
|
-
e.preventDefault();
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/** @private */
|
|
774
|
-
_onDrop(e) {
|
|
775
|
-
if (this._enabledCharPattern) {
|
|
776
|
-
const draggedText = e.dataTransfer.getData('text');
|
|
777
|
-
if (!this.__enabledTextRegExp.test(draggedText)) {
|
|
778
|
-
e.preventDefault();
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/** @private */
|
|
784
|
-
_onBeforeInput(e) {
|
|
785
|
-
// The `beforeinput` event covers all the cases for `_enabledCharPattern`: keyboard, pasting and dropping,
|
|
786
|
-
// but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
|
|
787
|
-
// because it seems to be the only way to detect and prevent specific keys on mobile devices. See issue #429.
|
|
788
|
-
if (this._enabledCharPattern && e.data && !this.__enabledTextRegExp.test(e.data)) {
|
|
789
|
-
e.preventDefault();
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/** @private */
|
|
794
|
-
__enabledCharPatternChanged(_enabledCharPattern) {
|
|
795
|
-
this.__enabledCharRegExp = _enabledCharPattern && new RegExp('^' + _enabledCharPattern + '$');
|
|
796
|
-
this.__enabledTextRegExp = _enabledCharPattern && new RegExp('^' + _enabledCharPattern + '*$');
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
/** @private */
|
|
800
|
-
_getActiveErrorId(invalid, errorMessage, errorId, helperText, helperTextId, hasSlottedHelper) {
|
|
801
|
-
const ids = [];
|
|
802
|
-
if (helperText || hasSlottedHelper) {
|
|
803
|
-
ids.push(helperTextId);
|
|
804
|
-
}
|
|
805
|
-
if (errorMessage && invalid) {
|
|
806
|
-
ids.push(errorId);
|
|
807
|
-
}
|
|
808
|
-
this._setOrToggleAttribute('aria-describedby', ids.join(' '), this.focusElement);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
/** @private */
|
|
812
|
-
_getActiveLabelId(label, _labelId, _inputId) {
|
|
813
|
-
let ids = _inputId;
|
|
814
|
-
if (label) {
|
|
815
|
-
ids = `${_labelId} ${_inputId}`;
|
|
816
|
-
}
|
|
817
|
-
this.focusElement.setAttribute('aria-labelledby', ids);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
/** @private */
|
|
821
|
-
_getErrorMessageAriaHidden(invalid, errorMessage, errorId) {
|
|
822
|
-
return (!(errorMessage && invalid ? errorId : undefined)).toString();
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/** @private */
|
|
826
|
-
_dispatchIronResizeEventIfNeeded(sizePropertyName, value) {
|
|
827
|
-
const previousSizePropertyName = '__previous' + sizePropertyName;
|
|
828
|
-
if (this[previousSizePropertyName] !== undefined && this[previousSizePropertyName] !== value) {
|
|
829
|
-
this.dispatchEvent(new CustomEvent('iron-resize', { bubbles: true, composed: true }));
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
this[previousSizePropertyName] = value;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
/** @private */
|
|
836
|
-
__observeOffsetHeight() {
|
|
837
|
-
this.__observeOffsetHeightDebouncer = Debouncer.debounce(
|
|
838
|
-
this.__observeOffsetHeightDebouncer,
|
|
839
|
-
animationFrame,
|
|
840
|
-
() => {
|
|
841
|
-
this._dispatchIronResizeEventIfNeeded('Height', this.offsetHeight);
|
|
842
|
-
}
|
|
843
|
-
);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// Workaround for https://github.com/Polymer/polymer/issues/5259
|
|
847
|
-
get __data() {
|
|
848
|
-
return this.__dataValue || {};
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
set __data(value) {
|
|
852
|
-
this.__dataValue = value;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
* Fired when the user commits a value change.
|
|
857
|
-
*
|
|
858
|
-
* @event change
|
|
859
|
-
*/
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* Fired when the value is changed by the user: on every typing keystroke,
|
|
863
|
-
* and the value is cleared using the clear button.
|
|
864
|
-
*
|
|
865
|
-
* @event input
|
|
866
|
-
*/
|
|
867
|
-
|
|
868
|
-
/**
|
|
869
|
-
* Fired when the size of the element changes.
|
|
870
|
-
*
|
|
871
|
-
* DEPRECATED: This event will be dropped in one of the future Vaadin versions. Use a ResizeObserver instead.
|
|
872
|
-
* @event iron-resize
|
|
873
|
-
*/
|
|
874
|
-
};
|