@vaadin/field-base 22.0.0-alpha6 → 22.0.0-alpha7
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 +6 -9
- package/index.js +6 -9
- package/package.json +22 -17
- package/src/aria-label-controller.d.ts +11 -0
- package/src/aria-label-controller.js +53 -0
- package/src/checked-mixin.js +37 -67
- package/src/delegate-focus-mixin.js +147 -131
- 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 +105 -86
- 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 +17 -89
- package/src/input-mixin.d.ts +1 -1
- package/src/input-mixin.js +156 -145
- package/src/label-mixin.d.ts +1 -1
- package/src/label-mixin.js +72 -59
- 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 +8 -19
- package/src/slot-target-mixin.js +93 -73
- 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 -120
- 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/field-aria-mixin.d.ts +0 -24
- package/src/field-aria-mixin.js +0 -61
- 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/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
|
@@ -4,104 +4,123 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
import {
|
|
7
|
+
import { DelegateStateMixin } from './delegate-state-mixin.js';
|
|
8
|
+
import { InputMixin } from './input-mixin.js';
|
|
9
|
+
import { ValidateMixin } from './validate-mixin.js';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A mixin to combine multiple input validation constraints.
|
|
13
|
+
*
|
|
14
|
+
* @polymerMixin
|
|
15
|
+
* @mixes DelegateStateMixin
|
|
16
|
+
* @mixes InputMixin
|
|
17
|
+
* @mixes ValidateMixin
|
|
18
|
+
*/
|
|
19
|
+
export const InputConstraintsMixin = dedupingMixin(
|
|
20
|
+
(superclass) =>
|
|
21
|
+
class InputConstraintsMixinClass extends DelegateStateMixin(ValidateMixin(InputMixin(superclass))) {
|
|
22
|
+
/**
|
|
23
|
+
* An array of attributes which participate in the input validation.
|
|
24
|
+
* Changing these attributes will cause the input to re-validate.
|
|
25
|
+
*
|
|
26
|
+
* IMPORTANT: The attributes should be properly delegated to the input element
|
|
27
|
+
* from the host using `delegateAttrs` getter (see `DelegateStateMixin`).
|
|
28
|
+
* The `required` attribute is already delegated.
|
|
29
|
+
*/
|
|
30
|
+
static get constraints() {
|
|
31
|
+
return ['required'];
|
|
32
|
+
}
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
static get delegateAttrs() {
|
|
35
|
+
return [...super.delegateAttrs, 'required'];
|
|
36
|
+
}
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
/** @protected */
|
|
39
|
+
ready() {
|
|
40
|
+
super.ready();
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
* Returns true if the current input value satisfies all constraints (if any).
|
|
34
|
-
* @return {boolean}
|
|
35
|
-
*/
|
|
36
|
-
checkValidity() {
|
|
37
|
-
if (this.inputElement && this.constructor.constraints.some((c) => this.__isValidConstraint(this[c]))) {
|
|
38
|
-
return this.inputElement.checkValidity();
|
|
39
|
-
} else {
|
|
40
|
-
return !this.invalid;
|
|
42
|
+
this._createConstraintsObserver();
|
|
41
43
|
}
|
|
42
|
-
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if the current input value satisfies all constraints (if any).
|
|
47
|
+
* @return {boolean}
|
|
48
|
+
*/
|
|
49
|
+
checkValidity() {
|
|
50
|
+
if (this.inputElement && this._hasValidConstraints(this.constructor.constraints.map((c) => this[c]))) {
|
|
51
|
+
return this.inputElement.checkValidity();
|
|
52
|
+
} else {
|
|
53
|
+
return !this.invalid;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!this.invalid) {
|
|
63
|
-
return;
|
|
57
|
+
/**
|
|
58
|
+
* Returns true if some of the provided set of constraints are valid.
|
|
59
|
+
* @param {Array} constraints
|
|
60
|
+
* @return {boolean}
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
_hasValidConstraints(constraints) {
|
|
64
|
+
return constraints.some((c) => this.__isValidConstraint(c));
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Override this method to customize setting up constraints observer.
|
|
69
|
+
* @protected
|
|
70
|
+
*/
|
|
71
|
+
_createConstraintsObserver() {
|
|
72
|
+
// This complex observer needs to be added dynamically instead of using `static get observers()`
|
|
73
|
+
// to make it possible to tweak this behavior in classes that apply this mixin.
|
|
74
|
+
this._createMethodObserver(`_constraintsChanged(${this.constructor.constraints.join(', ')})`);
|
|
70
75
|
}
|
|
71
|
-
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Override this method to implement custom validation constraints.
|
|
79
|
+
* @param {unknown[]} constraints
|
|
80
|
+
* @protected
|
|
81
|
+
*/
|
|
82
|
+
_constraintsChanged(...constraints) {
|
|
83
|
+
// Prevent marking field as invalid when setting required state
|
|
84
|
+
// or any other constraint before a user has entered the value.
|
|
85
|
+
if (!this.invalid) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
if (this._hasValidConstraints(constraints)) {
|
|
90
|
+
this.validate();
|
|
91
|
+
} else {
|
|
92
|
+
this.invalid = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Override an event listener inherited from `InputMixin`
|
|
98
|
+
* to capture native `change` event and make sure that
|
|
99
|
+
* a new one is dispatched after validation runs.
|
|
100
|
+
* @param {Event} event
|
|
101
|
+
* @protected
|
|
102
|
+
* @override
|
|
103
|
+
*/
|
|
104
|
+
_onChange(event) {
|
|
105
|
+
event.stopPropagation();
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
__isValidConstraint(constraint) {
|
|
99
|
-
// 0 is valid for `minlength` and `maxlength`
|
|
100
|
-
return Boolean(constraint) || constraint === 0;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
107
|
+
this.validate();
|
|
103
108
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
this.dispatchEvent(
|
|
110
|
+
new CustomEvent('change', {
|
|
111
|
+
detail: {
|
|
112
|
+
sourceEvent: event
|
|
113
|
+
},
|
|
114
|
+
bubbles: event.bubbles,
|
|
115
|
+
cancelable: event.cancelable
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @private */
|
|
121
|
+
__isValidConstraint(constraint) {
|
|
122
|
+
// 0 is valid for `minlength` and `maxlength`
|
|
123
|
+
return Boolean(constraint) || constraint === 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
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 { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
|
|
7
|
+
import { FieldMixin } from './field-mixin.js';
|
|
8
|
+
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin to provide shared logic for the editable form input controls.
|
|
12
|
+
*/
|
|
13
|
+
declare function InputControlMixin<T extends new (...args: any[]) => {}>(base: T): T & InputControlMixinConstructor;
|
|
14
|
+
|
|
15
|
+
interface InputControlMixinConstructor {
|
|
16
|
+
new (...args: any[]): InputControlMixin;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface InputControlMixin extends KeyboardMixin, InputConstraintsMixin, FieldMixin {
|
|
20
|
+
/**
|
|
21
|
+
* Specify that the value should be automatically selected when the field gains focus.
|
|
22
|
+
*/
|
|
23
|
+
autoselect: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Set to true to display the clear icon which clears the input.
|
|
27
|
+
* @attr {boolean} clear-button-visible
|
|
28
|
+
*/
|
|
29
|
+
clearButtonVisible: boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The name of this field.
|
|
33
|
+
*/
|
|
34
|
+
name: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A hint to the user of what can be entered in the field.
|
|
38
|
+
*/
|
|
39
|
+
placeholder: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* When present, it specifies that the field is read-only.
|
|
43
|
+
*/
|
|
44
|
+
readonly: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The text usually displayed in a tooltip popup when the mouse is over the field.
|
|
48
|
+
*/
|
|
49
|
+
title: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { InputControlMixin, InputControlMixinConstructor };
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
|
|
7
|
+
import { DelegateFocusMixin } from './delegate-focus-mixin.js';
|
|
8
|
+
import { FieldMixin } from './field-mixin.js';
|
|
9
|
+
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A mixin to provide shared logic for the editable form input controls.
|
|
13
|
+
*
|
|
14
|
+
* @polymerMixin
|
|
15
|
+
* @mixes DelegateFocusMixin
|
|
16
|
+
* @mixes FieldMixin
|
|
17
|
+
* @mixes InputConstraintsMixin
|
|
18
|
+
* @mixes KeyboardMixin
|
|
19
|
+
*/
|
|
20
|
+
export const InputControlMixin = (superclass) =>
|
|
21
|
+
class InputControlMixinClass extends DelegateFocusMixin(
|
|
22
|
+
InputConstraintsMixin(FieldMixin(KeyboardMixin(superclass)))
|
|
23
|
+
) {
|
|
24
|
+
static get properties() {
|
|
25
|
+
return {
|
|
26
|
+
/**
|
|
27
|
+
* Specify that the value should be automatically selected when the field gains focus.
|
|
28
|
+
*/
|
|
29
|
+
autoselect: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
value: false
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set to true to display the clear icon which clears the input.
|
|
36
|
+
* @attr {boolean} clear-button-visible
|
|
37
|
+
*/
|
|
38
|
+
clearButtonVisible: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
reflectToAttribute: true,
|
|
41
|
+
value: false
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The name of this field.
|
|
46
|
+
*/
|
|
47
|
+
name: {
|
|
48
|
+
type: String,
|
|
49
|
+
reflectToAttribute: true
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A hint to the user of what can be entered in the field.
|
|
54
|
+
*/
|
|
55
|
+
placeholder: {
|
|
56
|
+
type: String,
|
|
57
|
+
reflectToAttribute: true
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* When present, it specifies that the field is read-only.
|
|
62
|
+
*/
|
|
63
|
+
readonly: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
value: false,
|
|
66
|
+
reflectToAttribute: true
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The text usually displayed in a tooltip popup when the mouse is over the field.
|
|
71
|
+
*/
|
|
72
|
+
title: {
|
|
73
|
+
type: String,
|
|
74
|
+
reflectToAttribute: true
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static get delegateAttrs() {
|
|
80
|
+
return [...super.delegateAttrs, 'name', 'type', 'placeholder', 'readonly', 'invalid', 'title'];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Any element extending this mixin is required to implement this getter.
|
|
85
|
+
* It returns the reference to the clear button element.
|
|
86
|
+
* @protected
|
|
87
|
+
* @return {Element | null | undefined}
|
|
88
|
+
*/
|
|
89
|
+
get clearElement() {
|
|
90
|
+
console.warn(`Please implement the 'clearElement' property in <${this.localName}>`);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @protected */
|
|
95
|
+
ready() {
|
|
96
|
+
super.ready();
|
|
97
|
+
|
|
98
|
+
if (this.clearElement) {
|
|
99
|
+
this.clearElement.addEventListener('click', (e) => this._onClearButtonClick(e));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {Event} event
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
_onClearButtonClick(event) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
this.inputElement.focus();
|
|
110
|
+
this.clear();
|
|
111
|
+
this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
112
|
+
this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Override an event listener from `DelegateFocusMixin`.
|
|
117
|
+
* @param {FocusEvent} event
|
|
118
|
+
* @protected
|
|
119
|
+
* @override
|
|
120
|
+
*/
|
|
121
|
+
_onFocus(event) {
|
|
122
|
+
super._onFocus(event);
|
|
123
|
+
|
|
124
|
+
if (this.autoselect && this.inputElement) {
|
|
125
|
+
this.inputElement.select();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Override an event listener inherited from `KeydownMixin` to clear on Esc.
|
|
131
|
+
* Components that extend this mixin can prevent this behavior by overriding
|
|
132
|
+
* this method without calling `super._onKeyDown` to provide custom logic.
|
|
133
|
+
* @param {KeyboardEvent} event
|
|
134
|
+
* @protected
|
|
135
|
+
* @override
|
|
136
|
+
*/
|
|
137
|
+
_onKeyDown(event) {
|
|
138
|
+
super._onKeyDown(event);
|
|
139
|
+
|
|
140
|
+
if (event.key === 'Escape' && this.clearButtonVisible) {
|
|
141
|
+
const dispatchChange = !!this.value;
|
|
142
|
+
this.clear();
|
|
143
|
+
dispatchChange && this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Override an event listener inherited from `InputMixin`
|
|
149
|
+
* to capture native `change` event and make sure that
|
|
150
|
+
* a new one is dispatched after validation runs.
|
|
151
|
+
* @param {Event} event
|
|
152
|
+
* @protected
|
|
153
|
+
* @override
|
|
154
|
+
*/
|
|
155
|
+
_onChange(event) {
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
|
|
158
|
+
this.validate();
|
|
159
|
+
|
|
160
|
+
this.dispatchEvent(
|
|
161
|
+
new CustomEvent('change', {
|
|
162
|
+
detail: {
|
|
163
|
+
sourceEvent: event
|
|
164
|
+
},
|
|
165
|
+
bubbles: event.bubbles,
|
|
166
|
+
cancelable: event.cancelable
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { SlotController } from './slot-controller.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller to create and initialize slotted `<input>` element.
|
|
10
|
+
*/
|
|
11
|
+
export class InputController implements SlotController {}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { SlotController } from './slot-controller.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller to create and initialize slotted `<input>` element.
|
|
10
|
+
*/
|
|
11
|
+
export class InputController extends SlotController {
|
|
12
|
+
constructor(host, callback) {
|
|
13
|
+
super(host, [
|
|
14
|
+
'input',
|
|
15
|
+
() => document.createElement('input'),
|
|
16
|
+
(host, node) => {
|
|
17
|
+
if (host.value) {
|
|
18
|
+
node.setAttribute('value', host.value);
|
|
19
|
+
}
|
|
20
|
+
if (host.type) {
|
|
21
|
+
node.setAttribute('type', host.type);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Ensure every instance has unique ID
|
|
25
|
+
const uniqueId = (InputController._uniqueInputId = 1 + InputController._uniqueInputId || 0);
|
|
26
|
+
host._inputId = `${host.localName}-${uniqueId}`;
|
|
27
|
+
node.id = host._inputId;
|
|
28
|
+
|
|
29
|
+
if (typeof callback == 'function') {
|
|
30
|
+
callback(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -3,11 +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 {
|
|
7
|
-
import { ClearButtonMixin } from './clear-button-mixin.js';
|
|
8
|
-
import { DelegateFocusMixin } from './delegate-focus-mixin.js';
|
|
9
|
-
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
10
|
-
import { FieldAriaMixin } from './field-aria-mixin.js';
|
|
6
|
+
import { InputControlMixin } from './input-control-mixin.js';
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* A mixin to provide logic for vaadin-text-field and related components.
|
|
@@ -18,12 +14,7 @@ interface InputFieldMixinConstructor {
|
|
|
18
14
|
new (...args: any[]): InputFieldMixin;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
interface InputFieldMixin
|
|
22
|
-
extends AriaLabelMixin,
|
|
23
|
-
ClearButtonMixin,
|
|
24
|
-
DelegateFocusMixin,
|
|
25
|
-
FieldAriaMixin,
|
|
26
|
-
InputConstraintsMixin {
|
|
17
|
+
interface InputFieldMixin extends InputControlMixin {
|
|
27
18
|
/**
|
|
28
19
|
* Whether the value of the control can be automatically completed by the browser.
|
|
29
20
|
* List of available options at:
|
|
@@ -50,11 +41,6 @@ interface InputFieldMixin
|
|
|
50
41
|
* none: No capitalization.
|
|
51
42
|
*/
|
|
52
43
|
autocapitalize: 'on' | 'off' | 'none' | 'characters' | 'words' | 'sentences' | undefined;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Specify that the value should be automatically selected when the field gains focus.
|
|
56
|
-
*/
|
|
57
|
-
autoselect: boolean;
|
|
58
44
|
}
|
|
59
45
|
|
|
60
46
|
export { InputFieldMixin, InputFieldMixinConstructor };
|
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
|
-
import { animationFrame } from '@polymer/polymer/lib/utils/async.js';
|
|
8
|
-
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
9
|
-
import { AriaLabelMixin } from './aria-label-mixin.js';
|
|
10
|
-
import { ClearButtonMixin } from './clear-button-mixin.js';
|
|
11
|
-
import { DelegateFocusMixin } from './delegate-focus-mixin.js';
|
|
12
|
-
import { FieldAriaMixin } from './field-aria-mixin.js';
|
|
13
|
-
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
6
|
+
import { InputControlMixin } from './input-control-mixin.js';
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
/**
|
|
@@ -49,14 +46,6 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
49
46
|
*/
|
|
50
47
|
autocapitalize: {
|
|
51
48
|
type: String
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Specify that the value should be automatically selected when the field gains focus.
|
|
56
|
-
*/
|
|
57
|
-
autoselect: {
|
|
58
|
-
type: Boolean,
|
|
59
|
-
value: false
|
|
60
49
|
}
|
|
61
50
|
};
|
|
62
51
|
}
|
|
@@ -65,40 +54,23 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
65
54
|
return [...super.delegateAttrs, 'autocapitalize', 'autocomplete', 'autocorrect'];
|
|
66
55
|
}
|
|
67
56
|
|
|
68
|
-
static get observers() {
|
|
69
|
-
return ['__observeOffsetHeight(errorMessage, invalid, label, helperText)'];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
57
|
/**
|
|
73
|
-
*
|
|
58
|
+
* @param {HTMLElement} input
|
|
74
59
|
* @protected
|
|
60
|
+
* @override
|
|
75
61
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** @protected */
|
|
81
|
-
ready() {
|
|
82
|
-
super.ready();
|
|
62
|
+
_inputElementChanged(input) {
|
|
63
|
+
super._inputElementChanged(input);
|
|
83
64
|
|
|
84
|
-
|
|
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
|
-
}
|
|
92
|
-
|
|
93
|
-
if (this.inputElement) {
|
|
65
|
+
if (input) {
|
|
94
66
|
// Discard value set on the custom slotted input.
|
|
95
|
-
if (
|
|
67
|
+
if (input.value && input.value !== this.value) {
|
|
96
68
|
console.warn(`Please define value on the <${this.localName}> component!`);
|
|
97
|
-
|
|
69
|
+
input.value = '';
|
|
98
70
|
}
|
|
99
71
|
|
|
100
72
|
if (this.value) {
|
|
101
|
-
|
|
73
|
+
input.value = this.value;
|
|
102
74
|
}
|
|
103
75
|
}
|
|
104
76
|
}
|
|
@@ -112,20 +84,6 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
112
84
|
this.__dataValue = value;
|
|
113
85
|
}
|
|
114
86
|
|
|
115
|
-
/**
|
|
116
|
-
* Override an event listener from `DelegateFocusMixin`.
|
|
117
|
-
* @param {FocusEvent} event
|
|
118
|
-
* @protected
|
|
119
|
-
* @override
|
|
120
|
-
*/
|
|
121
|
-
_onFocus(event) {
|
|
122
|
-
super._onFocus(event);
|
|
123
|
-
|
|
124
|
-
if (this.autoselect && this.inputElement) {
|
|
125
|
-
this.inputElement.select();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
87
|
/**
|
|
130
88
|
* Override an event listener from `DelegateFocusMixin`.
|
|
131
89
|
* @param {FocusEvent} event
|
|
@@ -138,31 +96,6 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
138
96
|
this.validate();
|
|
139
97
|
}
|
|
140
98
|
|
|
141
|
-
/**
|
|
142
|
-
* Dispatch an event if a specific size measurement property has changed.
|
|
143
|
-
* Supporting multiple properties here is needed for `vaadin-text-area`.
|
|
144
|
-
* @protected
|
|
145
|
-
*/
|
|
146
|
-
_dispatchIronResizeEventIfNeeded(prop, value) {
|
|
147
|
-
const oldSize = '__old' + prop;
|
|
148
|
-
if (this[oldSize] !== undefined && this[oldSize] !== value) {
|
|
149
|
-
this.dispatchEvent(new CustomEvent('iron-resize', { bubbles: true, composed: true }));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
this[oldSize] = value;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** @private */
|
|
156
|
-
__observeOffsetHeight() {
|
|
157
|
-
this.__observeOffsetHeightDebouncer = Debouncer.debounce(
|
|
158
|
-
this.__observeOffsetHeightDebouncer,
|
|
159
|
-
animationFrame,
|
|
160
|
-
() => {
|
|
161
|
-
this._dispatchIronResizeEventIfNeeded('Height', this.offsetHeight);
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
99
|
/**
|
|
167
100
|
* Override a method from `InputMixin` to validate the field
|
|
168
101
|
* when a new value is set programmatically.
|
|
@@ -178,8 +111,3 @@ const InputFieldMixinImplementation = (superclass) =>
|
|
|
178
111
|
}
|
|
179
112
|
}
|
|
180
113
|
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* A mixin to provide logic for vaadin-text-field and related components.
|
|
184
|
-
*/
|
|
185
|
-
export const InputFieldMixin = dedupingMixin(InputFieldMixinImplementation);
|
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
|
*/
|