@vaadin/field-base 23.2.16 → 23.2.17
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 +3 -0
- package/index.js +3 -0
- package/package.json +4 -4
- package/src/checked-mixin.d.ts +2 -2
- package/src/checked-mixin.js +2 -2
- package/src/delegate-focus-mixin.d.ts +48 -0
- package/src/delegate-focus-mixin.js +228 -0
- package/src/delegate-state-mixin.d.ts +20 -0
- package/src/delegate-state-mixin.js +125 -0
- package/src/error-controller.d.ts +8 -3
- package/src/error-controller.js +65 -53
- package/src/field-aria-controller.d.ts +1 -1
- package/src/field-aria-controller.js +11 -11
- package/src/field-mixin.d.ts +1 -1
- package/src/field-mixin.js +28 -24
- package/src/helper-controller.d.ts +5 -3
- package/src/helper-controller.js +147 -47
- package/src/input-constraints-mixin.d.ts +4 -2
- package/src/input-constraints-mixin.js +2 -2
- package/src/input-control-mixin.d.ts +3 -3
- package/src/input-control-mixin.js +4 -4
- package/src/input-controller.d.ts +1 -1
- package/src/input-controller.js +8 -5
- package/src/input-field-mixin.d.ts +3 -3
- package/src/input-field-mixin.js +10 -10
- package/src/input-mixin.d.ts +3 -5
- package/src/input-mixin.js +10 -26
- package/src/label-controller.d.ts +8 -3
- package/src/label-controller.js +149 -45
- package/src/label-mixin.d.ts +1 -1
- package/src/label-mixin.js +8 -13
- package/src/labelled-input-controller.d.ts +1 -1
- package/src/labelled-input-controller.js +2 -2
- package/src/pattern-mixin.d.ts +13 -3
- package/src/pattern-mixin.js +50 -2
- package/src/shadow-focus-mixin.d.ts +23 -0
- package/src/shadow-focus-mixin.js +97 -0
- package/src/slot-styles-mixin.d.ts +1 -1
- package/src/slot-styles-mixin.js +1 -1
- package/src/slot-target-controller.d.ts +31 -0
- package/src/slot-target-controller.js +123 -0
- package/src/styles/clear-button-styles.d.ts +1 -1
- package/src/styles/clear-button-styles.js +2 -2
- package/src/styles/field-shared-styles.d.ts +1 -1
- package/src/styles/field-shared-styles.js +1 -1
- package/src/styles/input-field-container-styles.d.ts +1 -1
- package/src/styles/input-field-container-styles.js +1 -1
- package/src/styles/input-field-shared-styles.d.ts +1 -1
- package/src/styles/input-field-shared-styles.js +1 -1
- package/src/text-area-controller.d.ts +1 -1
- package/src/text-area-controller.js +8 -5
- package/src/validate-mixin.d.ts +1 -1
- package/src/validate-mixin.js +1 -1
- package/src/virtual-keyboard-controller.d.ts +1 -1
- package/src/virtual-keyboard-controller.js +1 -1
package/src/input-controller.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
@@ -10,8 +10,11 @@ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export class InputController extends SlotController {
|
|
12
12
|
constructor(host, callback) {
|
|
13
|
-
super(
|
|
14
|
-
|
|
13
|
+
super(
|
|
14
|
+
host,
|
|
15
|
+
'input',
|
|
16
|
+
() => document.createElement('input'),
|
|
17
|
+
(host, node) => {
|
|
15
18
|
if (host.value) {
|
|
16
19
|
node.setAttribute('value', host.value);
|
|
17
20
|
}
|
|
@@ -26,7 +29,7 @@ export class InputController extends SlotController {
|
|
|
26
29
|
callback(node);
|
|
27
30
|
}
|
|
28
31
|
},
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
true,
|
|
33
|
+
);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
7
|
import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
|
-
import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
|
|
9
|
-
import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
|
|
10
8
|
import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
11
9
|
import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
|
|
12
10
|
import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
|
|
11
|
+
import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
|
|
12
|
+
import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
|
|
13
13
|
import type { FieldMixinClass } from './field-mixin.js';
|
|
14
14
|
import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
|
|
15
15
|
import type { InputControlMixinClass } from './input-control-mixin.js';
|
package/src/input-field-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { InputControlMixin } from './input-control-mixin.js';
|
|
@@ -55,15 +55,6 @@ export const InputFieldMixin = (superclass) =>
|
|
|
55
55
|
return [...super.delegateAttrs, 'autocapitalize', 'autocomplete', 'autocorrect'];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
// Workaround for https://github.com/Polymer/polymer/issues/5259
|
|
59
|
-
get __data() {
|
|
60
|
-
return this.__dataValue || {};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
set __data(value) {
|
|
64
|
-
this.__dataValue = value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
58
|
/**
|
|
68
59
|
* @param {HTMLElement} input
|
|
69
60
|
* @protected
|
|
@@ -85,6 +76,15 @@ export const InputFieldMixin = (superclass) =>
|
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
|
|
79
|
+
// Workaround for https://github.com/Polymer/polymer/issues/5259
|
|
80
|
+
get __data() {
|
|
81
|
+
return this.__dataValue || {};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
set __data(value) {
|
|
85
|
+
this.__dataValue = value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
88
|
/**
|
|
89
89
|
* Override an event listener from `FocusMixin`.
|
|
90
90
|
* @param {boolean} focused
|
package/src/input-mixin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
@@ -47,15 +47,13 @@ export declare class InputMixinClass {
|
|
|
47
47
|
|
|
48
48
|
protected _inputElementChanged(input: HTMLElement, oldInput: HTMLElement): void;
|
|
49
49
|
|
|
50
|
-
protected _onChange(event:
|
|
50
|
+
protected _onChange(event: void): void;
|
|
51
51
|
|
|
52
|
-
protected _onInput(event:
|
|
52
|
+
protected _onInput(event: void): void;
|
|
53
53
|
|
|
54
54
|
protected _setInputElement(input: HTMLElement): void;
|
|
55
55
|
|
|
56
56
|
protected _toggleHasValue(hasValue: boolean): void;
|
|
57
57
|
|
|
58
58
|
protected _valueChanged(value?: string, oldValue?: string): void;
|
|
59
|
-
|
|
60
|
-
protected _setHasInputValue(event: InputEvent): void;
|
|
61
59
|
}
|
package/src/input-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
@@ -72,27 +72,11 @@ export const InputMixin = dedupingMixin(
|
|
|
72
72
|
this._boundOnChange = this._onChange.bind(this);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* Indicates whether the value is different from the default one.
|
|
77
|
-
* Override if the `value` property has a type other than `string`.
|
|
78
|
-
*
|
|
79
|
-
* @protected
|
|
80
|
-
*/
|
|
81
|
-
get _hasValue() {
|
|
82
|
-
return this.value != null && this.value !== '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
75
|
/**
|
|
86
76
|
* Clear the value of the field.
|
|
87
77
|
*/
|
|
88
78
|
clear() {
|
|
89
79
|
this.value = '';
|
|
90
|
-
|
|
91
|
-
// Clear the input immediately without waiting for the observer.
|
|
92
|
-
// Otherwise, when using Lit, the old value would be restored.
|
|
93
|
-
if (this.inputElement) {
|
|
94
|
-
this.inputElement.value = '';
|
|
95
|
-
}
|
|
96
80
|
}
|
|
97
81
|
|
|
98
82
|
/**
|
|
@@ -171,7 +155,11 @@ export const InputMixin = dedupingMixin(
|
|
|
171
155
|
* @private
|
|
172
156
|
*/
|
|
173
157
|
__onInput(event) {
|
|
174
|
-
|
|
158
|
+
// In the case a custom web component is passed as `inputElement`,
|
|
159
|
+
// the actual native input element, on which the event occurred,
|
|
160
|
+
// can be inside shadow trees.
|
|
161
|
+
const target = event.composedPath()[0];
|
|
162
|
+
this._hasInputValue = target.value.length > 0;
|
|
175
163
|
this._onInput(event);
|
|
176
164
|
}
|
|
177
165
|
|
|
@@ -234,17 +222,13 @@ export const InputMixin = dedupingMixin(
|
|
|
234
222
|
}
|
|
235
223
|
|
|
236
224
|
/**
|
|
237
|
-
*
|
|
225
|
+
* Indicates whether the value is different from the default one.
|
|
226
|
+
* Override if the `value` property has a type other than `string`.
|
|
238
227
|
*
|
|
239
|
-
* @param {InputEvent} event
|
|
240
228
|
* @protected
|
|
241
229
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// the actual native input element, on which the event occurred,
|
|
245
|
-
// can be inside shadow trees.
|
|
246
|
-
const target = event.composedPath()[0];
|
|
247
|
-
this._hasInputValue = target.value.length > 0;
|
|
230
|
+
get _hasValue() {
|
|
231
|
+
return this.value != null && this.value !== '';
|
|
248
232
|
}
|
|
249
233
|
},
|
|
250
234
|
);
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A controller to manage the label element.
|
|
10
10
|
*/
|
|
11
|
-
export class LabelController extends
|
|
11
|
+
export class LabelController extends SlotController {
|
|
12
|
+
/**
|
|
13
|
+
* ID attribute value set on the label element.
|
|
14
|
+
*/
|
|
15
|
+
labelId: string;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* String used for the label.
|
|
14
19
|
*/
|
package/src/label-controller.js
CHANGED
|
@@ -1,16 +1,77 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A controller to manage the label element.
|
|
10
10
|
*/
|
|
11
|
-
export class LabelController extends
|
|
11
|
+
export class LabelController extends SlotController {
|
|
12
12
|
constructor(host) {
|
|
13
|
-
super(
|
|
13
|
+
super(
|
|
14
|
+
host,
|
|
15
|
+
'label',
|
|
16
|
+
() => document.createElement('label'),
|
|
17
|
+
(_host, node) => {
|
|
18
|
+
// Set ID attribute or use the existing one.
|
|
19
|
+
this.__updateLabelId(node);
|
|
20
|
+
|
|
21
|
+
// Set text content for the default label.
|
|
22
|
+
this.__updateDefaultLabel(this.label);
|
|
23
|
+
|
|
24
|
+
this.__observeLabel(node);
|
|
25
|
+
},
|
|
26
|
+
true,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @return {string}
|
|
32
|
+
*/
|
|
33
|
+
get labelId() {
|
|
34
|
+
return this.node.id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Override to initialize the newly added custom label.
|
|
39
|
+
*
|
|
40
|
+
* @param {Node} labelNode
|
|
41
|
+
* @protected
|
|
42
|
+
* @override
|
|
43
|
+
*/
|
|
44
|
+
initCustomNode(labelNode) {
|
|
45
|
+
this.__updateLabelId(labelNode);
|
|
46
|
+
|
|
47
|
+
const hasLabel = this.__hasLabel(labelNode);
|
|
48
|
+
this.__toggleHasLabel(hasLabel);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Override to cleanup label node when it's removed.
|
|
53
|
+
*
|
|
54
|
+
* @param {Node} node
|
|
55
|
+
* @protected
|
|
56
|
+
* @override
|
|
57
|
+
*/
|
|
58
|
+
teardownNode(node) {
|
|
59
|
+
if (this.__labelObserver) {
|
|
60
|
+
this.__labelObserver.disconnect();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let labelNode = this.getSlotChild();
|
|
64
|
+
|
|
65
|
+
// If custom label was removed, restore the default one.
|
|
66
|
+
if (!labelNode && node !== this.defaultNode) {
|
|
67
|
+
labelNode = this.attachDefaultNode();
|
|
68
|
+
|
|
69
|
+
// Run initializer to update default label and ID.
|
|
70
|
+
this.initNode(labelNode);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const hasLabel = this.__hasLabel(labelNode);
|
|
74
|
+
this.__toggleHasLabel(hasLabel);
|
|
14
75
|
}
|
|
15
76
|
|
|
16
77
|
/**
|
|
@@ -21,65 +82,108 @@ export class LabelController extends SlotChildObserveController {
|
|
|
21
82
|
setLabel(label) {
|
|
22
83
|
this.label = label;
|
|
23
84
|
|
|
24
|
-
|
|
25
|
-
|
|
85
|
+
this.__updateDefaultLabel(label);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {HTMLElement} labelNode
|
|
90
|
+
* @return {boolean}
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
__hasLabel(labelNode) {
|
|
26
94
|
if (!labelNode) {
|
|
27
|
-
|
|
95
|
+
return false;
|
|
28
96
|
}
|
|
29
97
|
|
|
30
|
-
|
|
31
|
-
if (this.node === this.defaultNode) {
|
|
32
|
-
this.updateDefaultNode(this.node);
|
|
33
|
-
}
|
|
98
|
+
return labelNode.children.length > 0 || this.__isNotEmpty(labelNode.textContent);
|
|
34
99
|
}
|
|
35
100
|
|
|
36
101
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @protected
|
|
41
|
-
* @override
|
|
102
|
+
* @param {string} label
|
|
103
|
+
* @private
|
|
42
104
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
105
|
+
__isNotEmpty(label) {
|
|
106
|
+
return Boolean(label && label.trim() !== '');
|
|
107
|
+
}
|
|
45
108
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
109
|
+
/**
|
|
110
|
+
* @param {HTMLElement} labelNode
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
__observeLabel(labelNode) {
|
|
114
|
+
this.__labelObserver = new MutationObserver((mutations) => {
|
|
115
|
+
mutations.forEach((mutation) => {
|
|
116
|
+
const target = mutation.target;
|
|
49
117
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
118
|
+
// Ensure the mutation target is the currently connected label
|
|
119
|
+
// to ignore async mutations dispatched for removed element.
|
|
120
|
+
const isLabelMutation = target === this.node;
|
|
121
|
+
|
|
122
|
+
if (mutation.type === 'attributes') {
|
|
123
|
+
// We use attributeFilter to only observe ID mutation,
|
|
124
|
+
// no need to check for attribute name separately.
|
|
125
|
+
if (isLabelMutation && target.id !== this.defaultId) {
|
|
126
|
+
this.__updateLabelId(target);
|
|
127
|
+
}
|
|
128
|
+
} else if (isLabelMutation || target.parentElement === this.node) {
|
|
129
|
+
// Update has-label when textContent changes
|
|
130
|
+
const hasLabel = this.__hasLabel(this.node);
|
|
131
|
+
this.__toggleHasLabel(hasLabel);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Observe changes to label ID attribute, text content and children.
|
|
137
|
+
this.__labelObserver.observe(labelNode, {
|
|
138
|
+
attributes: true,
|
|
139
|
+
attributeFilter: ['id'],
|
|
140
|
+
childList: true,
|
|
141
|
+
subtree: true,
|
|
142
|
+
characterData: true,
|
|
143
|
+
});
|
|
53
144
|
}
|
|
54
145
|
|
|
55
146
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param {Node | undefined} node
|
|
60
|
-
* @protected
|
|
61
|
-
* @override
|
|
147
|
+
* @param {boolean} hasLabel
|
|
148
|
+
* @private
|
|
62
149
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
node.textContent = this.label;
|
|
66
|
-
}
|
|
150
|
+
__toggleHasLabel(hasLabel) {
|
|
151
|
+
this.host.toggleAttribute('has-label', hasLabel);
|
|
67
152
|
|
|
68
|
-
//
|
|
69
|
-
|
|
153
|
+
// Make it possible for other mixins to observe change
|
|
154
|
+
this.dispatchEvent(
|
|
155
|
+
new CustomEvent('label-changed', {
|
|
156
|
+
detail: {
|
|
157
|
+
hasLabel,
|
|
158
|
+
node: this.node,
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
70
162
|
}
|
|
71
163
|
|
|
72
164
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @param {Node} node
|
|
76
|
-
* @protected
|
|
77
|
-
* @override
|
|
165
|
+
* @param {string} label
|
|
166
|
+
* @private
|
|
78
167
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
168
|
+
__updateDefaultLabel(label) {
|
|
169
|
+
if (this.defaultNode) {
|
|
170
|
+
this.defaultNode.textContent = label;
|
|
171
|
+
|
|
172
|
+
// Update has-label if default label is used
|
|
173
|
+
if (this.defaultNode === this.node) {
|
|
174
|
+
const hasLabel = this.__isNotEmpty(label);
|
|
175
|
+
this.__toggleHasLabel(hasLabel);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
82
179
|
|
|
83
|
-
|
|
180
|
+
/**
|
|
181
|
+
* @param {HTMLElement} labelNode
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
__updateLabelId(labelNode) {
|
|
185
|
+
if (!labelNode.id) {
|
|
186
|
+
labelNode.id = this.defaultId;
|
|
187
|
+
}
|
|
84
188
|
}
|
|
85
189
|
}
|
package/src/label-mixin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
package/src/label-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
@@ -29,20 +29,9 @@ export const LabelMixin = dedupingMixin(
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
constructor() {
|
|
33
|
-
super();
|
|
34
|
-
|
|
35
|
-
this._labelController = new LabelController(this);
|
|
36
|
-
|
|
37
|
-
this._labelController.addEventListener('slot-content-changed', (event) => {
|
|
38
|
-
this.toggleAttribute('has-label', event.detail.hasContent);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
32
|
/** @protected */
|
|
43
33
|
get _labelId() {
|
|
44
|
-
|
|
45
|
-
return node && node.id;
|
|
34
|
+
return this._labelController.labelId;
|
|
46
35
|
}
|
|
47
36
|
|
|
48
37
|
/** @protected */
|
|
@@ -50,6 +39,12 @@ export const LabelMixin = dedupingMixin(
|
|
|
50
39
|
return this._labelController.node;
|
|
51
40
|
}
|
|
52
41
|
|
|
42
|
+
constructor() {
|
|
43
|
+
super();
|
|
44
|
+
|
|
45
|
+
this._labelController = new LabelController(this);
|
|
46
|
+
}
|
|
47
|
+
|
|
53
48
|
/** @protected */
|
|
54
49
|
ready() {
|
|
55
50
|
super.ready();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ export class LabelledInputController {
|
|
|
12
12
|
this.input = input;
|
|
13
13
|
this.__preventDuplicateLabelClick = this.__preventDuplicateLabelClick.bind(this);
|
|
14
14
|
|
|
15
|
-
labelController.addEventListener('
|
|
15
|
+
labelController.addEventListener('label-changed', (event) => {
|
|
16
16
|
this.__initLabel(event.detail.node);
|
|
17
17
|
});
|
|
18
18
|
|
package/src/pattern-mixin.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
-
import type {
|
|
7
|
+
import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
8
|
+
import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
|
|
8
9
|
import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
|
|
9
10
|
import type { InputMixinClass } from './input-mixin.js';
|
|
10
11
|
import type { ValidateMixinClass } from './validate-mixin.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* A mixin to provide `pattern`
|
|
14
|
+
* A mixin to provide `pattern` and `preventInvalidInput` properties.
|
|
14
15
|
*/
|
|
15
16
|
export declare function PatternMixin<T extends Constructor<HTMLElement>>(
|
|
16
17
|
base: T,
|
|
17
18
|
): Constructor<DelegateStateMixinClass> &
|
|
19
|
+
Constructor<DisabledMixinClass> &
|
|
18
20
|
Constructor<InputConstraintsMixinClass> &
|
|
19
21
|
Constructor<InputMixinClass> &
|
|
20
22
|
Constructor<PatternMixinClass> &
|
|
@@ -27,4 +29,12 @@ export declare class PatternMixinClass {
|
|
|
27
29
|
* The pattern must match the entire value, not just some subset.
|
|
28
30
|
*/
|
|
29
31
|
pattern: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* When set to true, user is prevented from typing a value that
|
|
35
|
+
* conflicts with the given `pattern`.
|
|
36
|
+
* @attr {boolean} prevent-invalid-input
|
|
37
|
+
* @deprecated Please use `allowedCharPattern` instead.
|
|
38
|
+
*/
|
|
39
|
+
preventInvalidInput: boolean | null | undefined;
|
|
30
40
|
}
|
package/src/pattern-mixin.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { timeOut } from '@vaadin/component-base/src/async.js';
|
|
7
|
+
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
6
8
|
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
* A mixin to provide `pattern`
|
|
11
|
+
* A mixin to provide `pattern` and `preventInvalidInput` properties.
|
|
10
12
|
*
|
|
11
13
|
* @polymerMixin
|
|
12
14
|
* @mixes InputConstraintsMixin
|
|
@@ -22,6 +24,17 @@ export const PatternMixin = (superclass) =>
|
|
|
22
24
|
pattern: {
|
|
23
25
|
type: String,
|
|
24
26
|
},
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* When set to true, user is prevented from typing a value that
|
|
30
|
+
* conflicts with the given `pattern`.
|
|
31
|
+
* @attr {boolean} prevent-invalid-input
|
|
32
|
+
* @deprecated Please use `allowedCharPattern` instead.
|
|
33
|
+
*/
|
|
34
|
+
preventInvalidInput: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
observer: '_preventInvalidInputChanged',
|
|
37
|
+
},
|
|
25
38
|
};
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -32,4 +45,39 @@ export const PatternMixin = (superclass) =>
|
|
|
32
45
|
static get constraints() {
|
|
33
46
|
return [...super.constraints, 'pattern'];
|
|
34
47
|
}
|
|
48
|
+
|
|
49
|
+
/** @private */
|
|
50
|
+
_checkInputValue() {
|
|
51
|
+
if (this.preventInvalidInput) {
|
|
52
|
+
const input = this.inputElement;
|
|
53
|
+
if (input && input.value.length > 0 && !this.checkValidity()) {
|
|
54
|
+
input.value = this.value || '';
|
|
55
|
+
// Add input-prevented attribute for 200ms
|
|
56
|
+
this.setAttribute('input-prevented', '');
|
|
57
|
+
this._inputDebouncer = Debouncer.debounce(this._inputDebouncer, timeOut.after(200), () => {
|
|
58
|
+
this.removeAttribute('input-prevented');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Event} event
|
|
66
|
+
* @protected
|
|
67
|
+
* @override
|
|
68
|
+
*/
|
|
69
|
+
_onInput(event) {
|
|
70
|
+
this._checkInputValue();
|
|
71
|
+
|
|
72
|
+
super._onInput(event);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @private */
|
|
76
|
+
_preventInvalidInputChanged(preventInvalidInput) {
|
|
77
|
+
if (preventInvalidInput) {
|
|
78
|
+
console.warn(
|
|
79
|
+
`WARNING: Since Vaadin 23.2, "preventInvalidInput" is deprecated. Please use "allowedCharPattern" instead.`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
35
83
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
8
|
+
import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
|
|
9
|
+
import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
|
|
10
|
+
import type { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
|
|
11
|
+
import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A mixin to forward focus to an element in the shadow DOM.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ShadowFocusMixin<T extends Constructor<HTMLElement>>(
|
|
17
|
+
base: T,
|
|
18
|
+
): Constructor<DelegateFocusMixinClass> &
|
|
19
|
+
Constructor<DisabledMixinClass> &
|
|
20
|
+
Constructor<FocusMixinClass> &
|
|
21
|
+
Constructor<KeyboardMixinClass> &
|
|
22
|
+
Constructor<TabindexMixinClass> &
|
|
23
|
+
T;
|