@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
|
@@ -0,0 +1,20 @@
|
|
|
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 { LabelMixin } from './label-mixin.js';
|
|
7
|
+
import { SlotTargetMixin } from './slot-target-mixin.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A mixin to forward any content from the default slot to the label node.
|
|
11
|
+
*/
|
|
12
|
+
declare function SlotLabelMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotLabelMixinConstructor;
|
|
13
|
+
|
|
14
|
+
interface SlotLabelMixinConstructor {
|
|
15
|
+
new (...args: any[]): SlotLabelMixin;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SlotLabelMixin extends SlotTargetMixin, LabelMixin {}
|
|
19
|
+
|
|
20
|
+
export { SlotLabelMixinConstructor, SlotLabelMixin };
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
+
import { LabelMixin } from './label-mixin.js';
|
|
8
|
+
import { SlotTargetMixin } from './slot-target-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin to forward any content from the default slot to the label node.
|
|
12
|
+
*
|
|
13
|
+
* @polymerMixin
|
|
14
|
+
* @mixes LabelMixin
|
|
15
|
+
* @mixes SlotTargetMixin
|
|
16
|
+
*/
|
|
17
|
+
export const SlotLabelMixin = dedupingMixin(
|
|
18
|
+
(superclass) =>
|
|
19
|
+
class SlotLabelMixinClass extends SlotTargetMixin(LabelMixin(superclass)) {
|
|
20
|
+
/** @protected */
|
|
21
|
+
get _slotTarget() {
|
|
22
|
+
return this._labelNode;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @protected */
|
|
26
|
+
ready() {
|
|
27
|
+
super.ready();
|
|
28
|
+
|
|
29
|
+
if (this._labelNode) {
|
|
30
|
+
// The default slot's content is moved to the label node
|
|
31
|
+
// only after `LabelMixin` is initialized which means
|
|
32
|
+
// we should manually toggle the `has-label` attribute
|
|
33
|
+
// respecting the new label content.
|
|
34
|
+
this._toggleHasLabelAttribute();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
);
|
package/src/slot-styles-mixin.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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
|
+
*/
|
|
1
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
2
7
|
|
|
3
8
|
const stylesMap = new WeakMap();
|
|
@@ -31,39 +36,41 @@ function insertStyles(styles, root) {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Mixin to insert styles into the outer scope to handle slotted components.
|
|
41
|
+
* This is useful e.g. to hide native `<input type="number">` controls.
|
|
42
|
+
*
|
|
43
|
+
* @polymerMixin
|
|
44
|
+
*/
|
|
45
|
+
export const SlotStylesMixin = dedupingMixin(
|
|
46
|
+
(superclass) =>
|
|
47
|
+
class SlotStylesMixinClass extends superclass {
|
|
48
|
+
/**
|
|
49
|
+
* List of styles to insert into root.
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
get slotStyles() {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
43
55
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
/** @protected */
|
|
57
|
+
connectedCallback() {
|
|
58
|
+
super.connectedCallback();
|
|
47
59
|
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
this.__applySlotStyles();
|
|
61
|
+
}
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
/** @private */
|
|
64
|
+
__applySlotStyles() {
|
|
65
|
+
const root = this.getRootNode();
|
|
66
|
+
const rootStyles = getRootStyles(root);
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
this.slotStyles.forEach((styles) => {
|
|
69
|
+
if (!rootStyles.has(styles)) {
|
|
70
|
+
insertStyles(styles, root);
|
|
71
|
+
rootStyles.add(styles);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
62
75
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Mixin to insert styles into the outer scope to handle slotted components.
|
|
67
|
-
* This is useful e.g. to hide native `<input type="number">` controls.
|
|
68
|
-
*/
|
|
69
|
-
export const SlotStylesMixin = dedupingMixin(SlotStylesMixinImplementation);
|
|
76
|
+
);
|
|
@@ -5,39 +5,28 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A mixin to
|
|
8
|
+
* A mixin to copy the content from a source slot to a target element.
|
|
9
9
|
*/
|
|
10
|
-
declare function
|
|
11
|
-
base: T
|
|
12
|
-
): T & SlotTargetMixinMixinConstructor;
|
|
10
|
+
declare function SlotTargetMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotTargetMixinConstructor;
|
|
13
11
|
|
|
14
|
-
interface
|
|
15
|
-
new (...args: any[]):
|
|
12
|
+
interface SlotTargetMixinConstructor {
|
|
13
|
+
new (...args: any[]): SlotTargetMixin;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
interface
|
|
16
|
+
interface SlotTargetMixin {
|
|
19
17
|
/**
|
|
20
|
-
* A reference to the source slot from which the content is
|
|
18
|
+
* A reference to the source slot from which the content is copied to the target element.
|
|
21
19
|
*
|
|
22
20
|
* @protected
|
|
23
21
|
*/
|
|
24
22
|
_sourceSlot: HTMLSlotElement;
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
|
-
* A reference to the target element to which the content is
|
|
25
|
+
* A reference to the target element to which the content is copied from the source slot.
|
|
28
26
|
*
|
|
29
27
|
* @protected
|
|
30
28
|
*/
|
|
31
29
|
_slotTarget: HTMLElement;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A callback method that is called once the target element's content is changed.
|
|
35
|
-
*
|
|
36
|
-
* By default, it does nothing. Override the method to implement your own behavior.
|
|
37
|
-
*
|
|
38
|
-
* @protected
|
|
39
|
-
*/
|
|
40
|
-
_onSlotTargetContentChange(): void;
|
|
41
30
|
}
|
|
42
31
|
|
|
43
|
-
export {
|
|
32
|
+
export { SlotTargetMixinConstructor, SlotTargetMixin };
|
package/src/slot-target-mixin.js
CHANGED
|
@@ -1,90 +1,110 @@
|
|
|
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
|
+
*/
|
|
1
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A mixin to copy the content from a source slot to a target element.
|
|
10
|
+
*
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
*/
|
|
13
|
+
export const SlotTargetMixin = dedupingMixin(
|
|
14
|
+
(superclass) =>
|
|
15
|
+
class SlotTargetMixinClass extends superclass {
|
|
16
|
+
/** @protected */
|
|
17
|
+
ready() {
|
|
18
|
+
super.ready();
|
|
7
19
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
this.__slotTargetObserver = new MutationObserver(() => {
|
|
13
|
-
this._onSlotTargetContentChange();
|
|
14
|
-
});
|
|
15
|
-
}
|
|
20
|
+
if (this._sourceSlot) {
|
|
21
|
+
this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
ready() {
|
|
19
|
-
super.ready();
|
|
23
|
+
this.__checkAndCopyNodesToSlotTarget();
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
25
|
+
this._sourceSlot.addEventListener('slotchange', () => {
|
|
26
|
+
this.__checkAndCopyNodesToSlotTarget();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* A reference to the source slot from which the nodes are copied to the target element.
|
|
33
|
+
*
|
|
34
|
+
* @type {HTMLSlotElement | null}
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
get _sourceSlot() {
|
|
38
|
+
console.warn(`Please implement the '_sourceSlot' property in <${this.localName}>`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
/**
|
|
43
|
+
* A reference to the target element to which the nodes are copied from the source slot.
|
|
44
|
+
*
|
|
45
|
+
* @type {HTMLElement | null}
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
get _slotTarget() {
|
|
49
|
+
console.warn(`Please implement the '_slotTarget' property in <${this.localName}>`);
|
|
50
|
+
return null;
|
|
35
51
|
}
|
|
36
|
-
}
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
53
|
+
/**
|
|
54
|
+
* Copies every node from the source slot to the target element
|
|
55
|
+
* once the source slot' content is changed.
|
|
56
|
+
*
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
__checkAndCopyNodesToSlotTarget() {
|
|
60
|
+
this.__sourceSlotObserver.disconnect();
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* @type {HTMLElement | null}
|
|
53
|
-
* @protected
|
|
54
|
-
*/
|
|
55
|
-
get _slotTarget() {
|
|
56
|
-
console.warn(`Please implement the '_slotTarget' property in <${this.localName}>`);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
62
|
+
if (!this._slotTarget) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Remove any existing clones from the slot target
|
|
67
|
+
if (this.__slotTargetClones) {
|
|
68
|
+
this.__slotTargetClones.forEach((node) => {
|
|
69
|
+
if (node.parentElement === this._slotTarget) {
|
|
70
|
+
this._slotTarget.removeChild(node);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
delete this.__slotTargetClones;
|
|
74
|
+
}
|
|
68
75
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// Exclude whitespace text nodes
|
|
77
|
+
const nodes = this._sourceSlot
|
|
78
|
+
.assignedNodes({ flatten: true })
|
|
79
|
+
.filter((node) => !(node.nodeType == Node.TEXT_NODE && node.textContent.trim() === ''));
|
|
80
|
+
|
|
81
|
+
if (nodes.length > 0) {
|
|
82
|
+
this._slotTarget.innerHTML = '';
|
|
83
|
+
this.__copyNodesToSlotTarget(nodes);
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Copies the nodes to the target element.
|
|
89
|
+
*
|
|
90
|
+
* @protected
|
|
91
|
+
* @param {!Array<!Node>} nodes
|
|
92
|
+
*/
|
|
93
|
+
__copyNodesToSlotTarget(nodes) {
|
|
94
|
+
this.__slotTargetClones = this.__slotTargetClones || [];
|
|
95
|
+
nodes.forEach((node) => {
|
|
96
|
+
// Clone the nodes and append the clones to the target slot
|
|
97
|
+
const clone = node.cloneNode(true);
|
|
98
|
+
this.__slotTargetClones.push(clone);
|
|
99
|
+
this._slotTarget.appendChild(clone);
|
|
100
|
+
// Observe all changes to the source node to have the clones updated
|
|
101
|
+
this.__sourceSlotObserver.observe(node, {
|
|
102
|
+
attributes: true,
|
|
103
|
+
childList: true,
|
|
104
|
+
subtree: true,
|
|
105
|
+
characterData: true
|
|
106
|
+
});
|
|
107
|
+
});
|
|
83
108
|
}
|
|
84
109
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* A mixin to forward the content from a source slot to a target element.
|
|
89
|
-
*/
|
|
90
|
-
export const SlotTargetMixin = dedupingMixin(SlotTargetMixinImplementation);
|
|
110
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
export const clearButton = css`
|
|
9
|
+
[part='clear-button'] {
|
|
10
|
+
display: none;
|
|
11
|
+
cursor: default;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
[part='clear-button']::before {
|
|
15
|
+
content: '✕';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
export const fieldShared = css`
|
|
9
|
+
:host {
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
outline: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:host::before {
|
|
15
|
+
content: '\\2003';
|
|
16
|
+
width: 0;
|
|
17
|
+
display: inline-block;
|
|
18
|
+
/* Size and position this element on the same vertical position as the input-field element
|
|
19
|
+
to make vertical align for the host element work as expected */
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:host([hidden]) {
|
|
23
|
+
display: none !important;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host(:not([has-label])) [part='label'] {
|
|
27
|
+
display: none;
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
export const inputFieldContainer = css`
|
|
9
|
+
[class$='container'] {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
min-width: 100%;
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
width: var(--vaadin-field-default-width, 12em);
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { clearButton } from './clear-button-styles.js';
|
|
7
|
+
import { fieldShared } from './field-shared-styles.js';
|
|
8
|
+
import { inputFieldContainer } from './input-field-container-styles.js';
|
|
9
|
+
|
|
10
|
+
export const inputFieldShared = [fieldShared, inputFieldContainer, clearButton];
|
|
@@ -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 `<textarea>` element.
|
|
10
|
+
*/
|
|
11
|
+
export class TextAreaController implements SlotController {}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 `<textarea>` element.
|
|
10
|
+
*/
|
|
11
|
+
export class TextAreaController extends SlotController {
|
|
12
|
+
constructor(host, callback) {
|
|
13
|
+
super(host, [
|
|
14
|
+
'textarea',
|
|
15
|
+
() => document.createElement('textarea'),
|
|
16
|
+
(host, node) => {
|
|
17
|
+
const value = host.getAttribute('value');
|
|
18
|
+
if (value) {
|
|
19
|
+
node.value = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const name = host.getAttribute('name');
|
|
23
|
+
if (name) {
|
|
24
|
+
node.setAttribute('name', name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Ensure every instance has unique ID
|
|
28
|
+
const uniqueId = (TextAreaController._uniqueTextAreaId = 1 + TextAreaController._uniqueInputId || 0);
|
|
29
|
+
host._textareaId = `${host.localName}-${uniqueId}`;
|
|
30
|
+
node.id = host._textareaId;
|
|
31
|
+
|
|
32
|
+
if (typeof callback == 'function') {
|
|
33
|
+
callback(node);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/validate-mixin.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
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 '@vaadin/component-base/src/slot-mixin.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* A mixin to provide required state and validation logic.
|
|
@@ -14,7 +13,7 @@ interface ValidateMixinConstructor {
|
|
|
14
13
|
new (...args: any[]): ValidateMixin;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
interface ValidateMixin
|
|
16
|
+
interface ValidateMixin {
|
|
18
17
|
/**
|
|
19
18
|
* Set to true when the field is invalid.
|
|
20
19
|
*/
|
|
@@ -25,13 +24,6 @@ interface ValidateMixin extends SlotMixin {
|
|
|
25
24
|
*/
|
|
26
25
|
required: boolean;
|
|
27
26
|
|
|
28
|
-
/**
|
|
29
|
-
* Error to show when the field is invalid.
|
|
30
|
-
*
|
|
31
|
-
* @attr {string} error-message
|
|
32
|
-
*/
|
|
33
|
-
errorMessage: string;
|
|
34
|
-
|
|
35
27
|
/**
|
|
36
28
|
* Returns true if field is valid, and sets `invalid` based on the field validity.
|
|
37
29
|
*/
|