@vaadin/field-base 22.0.0-alpha3 → 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 +9 -14
- package/index.js +9 -14
- package/package.json +24 -18
- package/src/aria-label-controller.d.ts +11 -0
- package/src/aria-label-controller.js +53 -0
- package/src/checked-mixin.d.ts +21 -0
- package/src/checked-mixin.js +54 -0
- package/src/delegate-focus-mixin.d.ts +2 -2
- package/src/delegate-focus-mixin.js +150 -133
- package/src/delegate-state-mixin.d.ts +23 -0
- package/src/delegate-state-mixin.js +125 -0
- package/src/field-mixin.d.ts +39 -0
- package/src/field-mixin.js +317 -0
- package/src/input-constraints-mixin.d.ts +2 -1
- package/src/input-constraints-mixin.js +105 -53
- 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 +20 -97
- package/src/input-mixin.d.ts +1 -1
- package/src/input-mixin.js +156 -145
- package/src/label-mixin.d.ts +2 -2
- package/src/label-mixin.js +73 -60
- package/src/pattern-mixin.d.ts +2 -2
- package/src/pattern-mixin.js +13 -13
- 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.d.ts +24 -0
- package/src/slot-styles-mixin.js +76 -0
- package/src/slot-target-mixin.d.ts +32 -0
- package/src/slot-target-mixin.js +110 -0
- package/src/styles/clear-button-styles.d.ts +8 -0
- package/src/styles/clear-button-styles.js +21 -0
- package/src/styles/field-shared-styles.d.ts +8 -0
- package/src/styles/field-shared-styles.js +29 -0
- package/src/styles/input-field-container-styles.d.ts +8 -0
- package/src/styles/input-field-container-styles.js +16 -0
- package/src/styles/input-field-shared-styles.d.ts +8 -0
- package/src/styles/input-field-shared-styles.js +10 -0
- package/src/text-area-controller.d.ts +11 -0
- package/src/text-area-controller.js +38 -0
- package/src/validate-mixin.d.ts +1 -9
- package/src/validate-mixin.js +43 -118
- package/src/active-mixin.d.ts +0 -25
- package/src/active-mixin.js +0 -84
- 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 -27
- package/src/clear-button-mixin.js +0 -80
- package/src/disabled-mixin.d.ts +0 -23
- package/src/disabled-mixin.js +0 -48
- package/src/field-aria-mixin.d.ts +0 -24
- package/src/field-aria-mixin.js +0 -61
- package/src/focus-mixin.d.ts +0 -33
- package/src/focus-mixin.js +0 -104
- package/src/forward-input-props-mixin.d.ts +0 -41
- package/src/forward-input-props-mixin.js +0 -110
- package/src/helper-text-mixin.d.ts +0 -24
- package/src/helper-text-mixin.js +0 -109
- package/src/input-slot-mixin.d.ts +0 -26
- package/src/input-slot-mixin.js +0 -71
- package/src/slot-mixin.d.ts +0 -23
- package/src/slot-mixin.js +0 -55
- package/src/tabindex-mixin.d.ts +0 -29
- package/src/tabindex-mixin.js +0 -78
- package/src/text-area-slot-mixin.d.ts +0 -21
- package/src/text-area-slot-mixin.js +0 -56
- package/src/text-field-mixin.d.ts +0 -21
- package/src/text-field-mixin.js +0 -17
package/src/field-aria-mixin.js
DELETED
|
@@ -1,61 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
import { HelperTextMixin } from './helper-text-mixin.js';
|
|
8
|
-
import { ValidateMixin } from './validate-mixin.js';
|
|
9
|
-
|
|
10
|
-
const FieldAriaMixinImplementation = (superclass) =>
|
|
11
|
-
class FieldAriaMixinClass extends HelperTextMixin(ValidateMixin(superclass)) {
|
|
12
|
-
/** @protected */
|
|
13
|
-
get _ariaTarget() {
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @protected */
|
|
18
|
-
get _ariaAttr() {
|
|
19
|
-
return 'aria-describedby';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static get observers() {
|
|
23
|
-
return ['_invalidChanged(invalid)'];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** @protected */
|
|
27
|
-
connectedCallback() {
|
|
28
|
-
super.connectedCallback();
|
|
29
|
-
|
|
30
|
-
this._updateAriaAttribute(this.invalid);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** @protected */
|
|
34
|
-
_updateAriaAttribute(invalid) {
|
|
35
|
-
const attr = this._ariaAttr;
|
|
36
|
-
|
|
37
|
-
if (this._ariaTarget && attr) {
|
|
38
|
-
// For groups, add all IDs to aria-labelledby rather than aria-describedby -
|
|
39
|
-
// that should guarantee that it's announced when the group is entered.
|
|
40
|
-
const ariaIds = attr === 'aria-describedby' ? [this._helperId] : [this._labelId, this._helperId];
|
|
41
|
-
|
|
42
|
-
// Error message ID needs to be dynamically added / removed based on the validity
|
|
43
|
-
// Otherwise assistive technologies would announce the error, even if we hide it.
|
|
44
|
-
if (invalid) {
|
|
45
|
-
ariaIds.push(this._errorId);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this._ariaTarget.setAttribute(attr, ariaIds.join(' '));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @protected */
|
|
53
|
-
_invalidChanged(invalid) {
|
|
54
|
-
this._updateAriaAttribute(invalid);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A mixin to handle field ARIA attributes based on the label, error message and helper text.
|
|
60
|
-
*/
|
|
61
|
-
export const FieldAriaMixin = dedupingMixin(FieldAriaMixinImplementation);
|
package/src/focus-mixin.d.ts
DELETED
|
@@ -1,33 +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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A mixin to handle `focused` and `focus-ring` attributes based on focus.
|
|
9
|
-
*/
|
|
10
|
-
declare function FocusMixin<T extends new (...args: any[]) => {}>(base: T): T & FocusMixinConstructor;
|
|
11
|
-
|
|
12
|
-
interface FocusMixinConstructor {
|
|
13
|
-
new (...args: any[]): FocusMixin;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface FocusMixin {
|
|
17
|
-
/**
|
|
18
|
-
* Override to change how focused and focus-ring attributes are set.
|
|
19
|
-
*/
|
|
20
|
-
_setFocused(focused: boolean): void;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Override to define if the field receives focus based on the event.
|
|
24
|
-
*/
|
|
25
|
-
_shouldSetFocus(event: FocusEvent): boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Override to define if the field loses focus based on the event.
|
|
29
|
-
*/
|
|
30
|
-
_shouldRemoveFocus(event: FocusEvent): boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { FocusMixinConstructor, FocusMixin };
|
package/src/focus-mixin.js
DELETED
|
@@ -1,104 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
|
|
8
|
-
// We consider the keyboard to be active if the window has received a keydown
|
|
9
|
-
// event since the last mousedown event.
|
|
10
|
-
let keyboardActive = false;
|
|
11
|
-
|
|
12
|
-
// Listen for top-level keydown and mousedown events.
|
|
13
|
-
// Use capture phase so we detect events even if they're handled.
|
|
14
|
-
window.addEventListener(
|
|
15
|
-
'keydown',
|
|
16
|
-
() => {
|
|
17
|
-
keyboardActive = true;
|
|
18
|
-
},
|
|
19
|
-
{ capture: true }
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
window.addEventListener(
|
|
23
|
-
'mousedown',
|
|
24
|
-
() => {
|
|
25
|
-
keyboardActive = false;
|
|
26
|
-
},
|
|
27
|
-
{ capture: true }
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const FocusMixinImplementation = (superclass) =>
|
|
31
|
-
class FocusMixinClass extends superclass {
|
|
32
|
-
/** @protected */
|
|
33
|
-
ready() {
|
|
34
|
-
this.addEventListener('focusin', (e) => {
|
|
35
|
-
if (this._shouldSetFocus(e)) {
|
|
36
|
-
this._setFocused(true);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this.addEventListener('focusout', (e) => {
|
|
41
|
-
if (this._shouldRemoveFocus(e)) {
|
|
42
|
-
this._setFocused(false);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// In super.ready() other 'focusin' and 'focusout' listeners might be
|
|
47
|
-
// added, so we call it after our own ones to ensure they execute first.
|
|
48
|
-
// Issue to watch out: when incorrect, <vaadin-combo-box> refocuses the
|
|
49
|
-
// input field on iOS after “Done” is pressed.
|
|
50
|
-
super.ready();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** @protected */
|
|
54
|
-
disconnectedCallback() {
|
|
55
|
-
super.disconnectedCallback();
|
|
56
|
-
|
|
57
|
-
// in non-Chrome browsers, blur does not fire on the element when it is disconnected.
|
|
58
|
-
// reproducible in `<vaadin-date-picker>` when closing on `Cancel` or `Today` click.
|
|
59
|
-
if (this.hasAttribute('focused')) {
|
|
60
|
-
this._setFocused(false);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Override to change how focused and focus-ring attributes are set.
|
|
66
|
-
*
|
|
67
|
-
* @param {boolean} focused
|
|
68
|
-
* @protected
|
|
69
|
-
*/
|
|
70
|
-
_setFocused(focused) {
|
|
71
|
-
this.toggleAttribute('focused', focused);
|
|
72
|
-
|
|
73
|
-
// focus-ring is true when the element was focused from the keyboard.
|
|
74
|
-
// Focus Ring [A11ycasts]: https://youtu.be/ilj2P5-5CjI
|
|
75
|
-
this.toggleAttribute('focus-ring', focused && keyboardActive);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Override to define if the field receives focus based on the event.
|
|
80
|
-
*
|
|
81
|
-
* @param {FocusEvent} event
|
|
82
|
-
* @return {boolean}
|
|
83
|
-
* @protected
|
|
84
|
-
*/
|
|
85
|
-
_shouldSetFocus(_event) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Override to define if the field loses focus based on the event.
|
|
91
|
-
*
|
|
92
|
-
* @param {FocusEvent} event
|
|
93
|
-
* @return {boolean}
|
|
94
|
-
* @protected
|
|
95
|
-
*/
|
|
96
|
-
_shouldRemoveFocus(_event) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* A mixin to handle `focused` and `focus-ring` attributes based on focus.
|
|
103
|
-
*/
|
|
104
|
-
export const FocusMixin = dedupingMixin(FocusMixinImplementation);
|
|
@@ -1,41 +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 { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin to forward properties to the input element.
|
|
10
|
-
*/
|
|
11
|
-
declare function ForwardInputPropsMixin<T extends new (...args: any[]) => {}>(
|
|
12
|
-
base: T
|
|
13
|
-
): T & ForwardInputPropsMixinConstructor;
|
|
14
|
-
|
|
15
|
-
interface ForwardInputPropsMixinConstructor {
|
|
16
|
-
new (...args: any[]): ForwardInputPropsMixin;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ForwardInputPropsMixin extends InputConstraintsMixin {
|
|
20
|
-
/**
|
|
21
|
-
* The name of this field.
|
|
22
|
-
*/
|
|
23
|
-
name: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A hint to the user of what can be entered in the field.
|
|
27
|
-
*/
|
|
28
|
-
placeholder: string;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* When present, it specifies that the field is read-only.
|
|
32
|
-
*/
|
|
33
|
-
readonly: boolean;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The text usually displayed in a tooltip popup when the mouse is over the field.
|
|
37
|
-
*/
|
|
38
|
-
title: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { ForwardInputPropsMixinConstructor, ForwardInputPropsMixin };
|
|
@@ -1,110 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
import { InputConstraintsMixin } from './input-constraints-mixin.js';
|
|
8
|
-
|
|
9
|
-
const ForwardInputPropsMixinImplementation = (superclass) =>
|
|
10
|
-
class ForwardInputPropsMixinClass extends InputConstraintsMixin(superclass) {
|
|
11
|
-
static get properties() {
|
|
12
|
-
return {
|
|
13
|
-
/**
|
|
14
|
-
* The name of this field.
|
|
15
|
-
*/
|
|
16
|
-
name: {
|
|
17
|
-
type: String
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A hint to the user of what can be entered in the field.
|
|
22
|
-
*/
|
|
23
|
-
placeholder: {
|
|
24
|
-
type: String
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* When present, it specifies that the field is read-only.
|
|
29
|
-
*/
|
|
30
|
-
readonly: {
|
|
31
|
-
type: Boolean,
|
|
32
|
-
value: false,
|
|
33
|
-
reflectToAttribute: true
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The text usually displayed in a tooltip popup when the mouse is over the field.
|
|
38
|
-
*/
|
|
39
|
-
title: {
|
|
40
|
-
type: String
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static get forwardProps() {
|
|
46
|
-
return ['name', 'type', 'placeholder', 'readonly', 'required', 'invalid', 'title'];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @protected */
|
|
50
|
-
ready() {
|
|
51
|
-
// Create observer dynamically to allow subclasses to override forwardProps
|
|
52
|
-
// Note, this needs to be done before calling `super.ready()` to propagate changes
|
|
53
|
-
// to the validation constraints, e.g. when setting `required` property to `false`,
|
|
54
|
-
// before the observer created by `InputConstraintsMixin` to validate properly.
|
|
55
|
-
this._createMethodObserver(`_forwardPropsChanged(${this.constructor.forwardProps.join(', ')})`);
|
|
56
|
-
|
|
57
|
-
super.ready();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** @protected */
|
|
61
|
-
_inputElementChanged(input) {
|
|
62
|
-
super._inputElementChanged(input);
|
|
63
|
-
|
|
64
|
-
if (input) {
|
|
65
|
-
// Propagate initially defined properties to the slotted input
|
|
66
|
-
this._propagateHostAttributes(
|
|
67
|
-
this.constructor.forwardProps.map((attr) => this[attr] || this.getAttribute(attr))
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @private */
|
|
73
|
-
_forwardPropsChanged(...attributesValues) {
|
|
74
|
-
this._propagateHostAttributes(attributesValues);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** @private */
|
|
78
|
-
_propagateHostAttributes(attributesValues) {
|
|
79
|
-
const input = this.inputElement;
|
|
80
|
-
const attributeNames = this.constructor.forwardProps;
|
|
81
|
-
|
|
82
|
-
attributeNames.forEach((attr, index) => {
|
|
83
|
-
const value = attributesValues[index];
|
|
84
|
-
if (attr === 'invalid') {
|
|
85
|
-
this._setOrToggleAttribute(attr, value, input);
|
|
86
|
-
this._setOrToggleAttribute('aria-invalid', value ? 'true' : false, input);
|
|
87
|
-
} else {
|
|
88
|
-
this._setOrToggleAttribute(attr, value, input);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** @protected */
|
|
94
|
-
_setOrToggleAttribute(name, value, node) {
|
|
95
|
-
if (!name || !node) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (value) {
|
|
100
|
-
node.setAttribute(name, typeof value === 'boolean' ? '' : value);
|
|
101
|
-
} else {
|
|
102
|
-
node.removeAttribute(name);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* A mixin to forward properties to the input element.
|
|
109
|
-
*/
|
|
110
|
-
export const ForwardInputPropsMixin = dedupingMixin(ForwardInputPropsMixinImplementation);
|
|
@@ -1,24 +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 { SlotMixin } from './slot-mixin.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin to provide helper text via corresponding property or named slot.
|
|
10
|
-
*/
|
|
11
|
-
declare function HelperTextMixin<T extends new (...args: any[]) => {}>(base: T): T & HelperTextMixinConstructor;
|
|
12
|
-
|
|
13
|
-
interface HelperTextMixinConstructor {
|
|
14
|
-
new (...args: any[]): HelperTextMixin;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface HelperTextMixin extends SlotMixin {
|
|
18
|
-
/**
|
|
19
|
-
* String used for the helper text.
|
|
20
|
-
*/
|
|
21
|
-
helperText: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { HelperTextMixinConstructor, HelperTextMixin };
|
package/src/helper-text-mixin.js
DELETED
|
@@ -1,109 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
import { SlotMixin } from './slot-mixin.js';
|
|
8
|
-
|
|
9
|
-
const HelperTextMixinImplementation = (superclass) =>
|
|
10
|
-
class HelperTextMixinClass extends SlotMixin(superclass) {
|
|
11
|
-
static get properties() {
|
|
12
|
-
return {
|
|
13
|
-
/**
|
|
14
|
-
* String used for the helper text.
|
|
15
|
-
* @attr {string} helper-text
|
|
16
|
-
*/
|
|
17
|
-
helperText: {
|
|
18
|
-
type: String,
|
|
19
|
-
observer: '_helperTextChanged'
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get slots() {
|
|
25
|
-
return {
|
|
26
|
-
...super.slots,
|
|
27
|
-
helper: () => {
|
|
28
|
-
const helper = document.createElement('div');
|
|
29
|
-
helper.textContent = this.helperText;
|
|
30
|
-
return helper;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @protected */
|
|
36
|
-
get _helperNode() {
|
|
37
|
-
return this._getDirectSlotChild('helper');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
constructor() {
|
|
41
|
-
super();
|
|
42
|
-
|
|
43
|
-
// Ensure every instance has unique ID
|
|
44
|
-
const uniqueId = (HelperTextMixinClass._uniqueId = 1 + HelperTextMixinClass._uniqueId || 0);
|
|
45
|
-
this._helperId = `helper-${this.localName}-${uniqueId}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** @protected */
|
|
49
|
-
connectedCallback() {
|
|
50
|
-
super.connectedCallback();
|
|
51
|
-
|
|
52
|
-
if (this._helperNode) {
|
|
53
|
-
this._currentHelper = this._helperNode;
|
|
54
|
-
this._helperNode.id = this._helperId;
|
|
55
|
-
|
|
56
|
-
this._applyCustomHelper();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** @protected */
|
|
61
|
-
ready() {
|
|
62
|
-
super.ready();
|
|
63
|
-
|
|
64
|
-
this.__helperSlot = this.shadowRoot.querySelector('[name="helper"]');
|
|
65
|
-
this.__helperSlot.addEventListener('slotchange', this.__onHelperSlotChange.bind(this));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** @private */
|
|
69
|
-
__onHelperSlotChange() {
|
|
70
|
-
// Check fot slotted element node that is not the one created by this mixin.
|
|
71
|
-
const customHelper = this.__helperSlot
|
|
72
|
-
.assignedElements({ flatten: true })
|
|
73
|
-
.find((node) => node !== this._currentHelper);
|
|
74
|
-
|
|
75
|
-
if (customHelper) {
|
|
76
|
-
customHelper.id = this._helperId;
|
|
77
|
-
|
|
78
|
-
if (this._currentHelper.isConnected) {
|
|
79
|
-
this._currentHelper.remove();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this._applyCustomHelper();
|
|
83
|
-
|
|
84
|
-
this._currentHelper = customHelper;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** @protected */
|
|
89
|
-
_applyCustomHelper() {
|
|
90
|
-
const helper = this._helperNode.textContent;
|
|
91
|
-
if (helper !== this.helperText) {
|
|
92
|
-
this.helperText = helper;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** @protected */
|
|
97
|
-
_helperTextChanged(helper) {
|
|
98
|
-
if (this._helperNode) {
|
|
99
|
-
this._helperNode.textContent = helper;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.toggleAttribute('has-helper', Boolean(helper));
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* A mixin to provide helper text via corresponding property or named slot.
|
|
108
|
-
*/
|
|
109
|
-
export const HelperTextMixin = dedupingMixin(HelperTextMixinImplementation);
|
|
@@ -1,26 +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 { DelegatesFocusMixin } from './delegate-focus-mixin.js';
|
|
7
|
-
import { SlotMixin } from './slot-mixin.js';
|
|
8
|
-
import { InputMixin } from './input-mixin.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A mixin to add `<input>` element to the corresponding named slot.
|
|
12
|
-
*/
|
|
13
|
-
declare function InputSlotMixin<T extends new (...args: any[]) => {}>(base: T): T & InputSlotMixinConstructor;
|
|
14
|
-
|
|
15
|
-
interface InputSlotMixinConstructor {
|
|
16
|
-
new (...args: any[]): InputSlotMixin;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface InputSlotMixin extends DelegatesFocusMixin, InputMixin, SlotMixin {
|
|
20
|
-
/**
|
|
21
|
-
* String used to define input type.
|
|
22
|
-
*/
|
|
23
|
-
readonly type: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { InputSlotMixinConstructor, InputSlotMixin };
|
package/src/input-slot-mixin.js
DELETED
|
@@ -1,71 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
import { DelegateFocusMixin } from './delegate-focus-mixin.js';
|
|
8
|
-
import { InputMixin } from './input-mixin.js';
|
|
9
|
-
import { SlotMixin } from './slot-mixin.js';
|
|
10
|
-
|
|
11
|
-
const InputSlotMixinImplementation = (superclass) =>
|
|
12
|
-
class InputSlotMixinClass extends DelegateFocusMixin(InputMixin(SlotMixin(superclass))) {
|
|
13
|
-
static get properties() {
|
|
14
|
-
/**
|
|
15
|
-
* String used to define input type.
|
|
16
|
-
*/
|
|
17
|
-
return {
|
|
18
|
-
type: {
|
|
19
|
-
type: String,
|
|
20
|
-
readOnly: true
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get slots() {
|
|
26
|
-
return {
|
|
27
|
-
...super.slots,
|
|
28
|
-
input: () => {
|
|
29
|
-
const native = document.createElement('input');
|
|
30
|
-
const value = this.getAttribute('value');
|
|
31
|
-
if (value) {
|
|
32
|
-
native.setAttribute('value', value);
|
|
33
|
-
}
|
|
34
|
-
const name = this.getAttribute('name');
|
|
35
|
-
if (name) {
|
|
36
|
-
native.setAttribute('name', name);
|
|
37
|
-
}
|
|
38
|
-
if (this.type) {
|
|
39
|
-
native.setAttribute('type', this.type);
|
|
40
|
-
}
|
|
41
|
-
return native;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
constructor() {
|
|
47
|
-
super();
|
|
48
|
-
|
|
49
|
-
// Ensure every instance has unique ID
|
|
50
|
-
const uniqueId = (InputSlotMixinClass._uniqueId = 1 + InputSlotMixinClass._uniqueId || 0);
|
|
51
|
-
this._inputId = `${this.localName}-${uniqueId}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @protected */
|
|
55
|
-
connectedCallback() {
|
|
56
|
-
super.connectedCallback();
|
|
57
|
-
|
|
58
|
-
const inputNode = this._getDirectSlotChild('input');
|
|
59
|
-
if (inputNode) {
|
|
60
|
-
inputNode.id = this._inputId;
|
|
61
|
-
|
|
62
|
-
this._setInputElement(inputNode);
|
|
63
|
-
this._setFocusElement(inputNode);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* A mixin to add `<input>` element to the corresponding named slot.
|
|
70
|
-
*/
|
|
71
|
-
export const InputSlotMixin = dedupingMixin(InputSlotMixinImplementation);
|
package/src/slot-mixin.d.ts
DELETED
|
@@ -1,23 +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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A mixin to provide content for named slots defined by component.
|
|
9
|
-
*/
|
|
10
|
-
declare function SlotMixin<T extends new (...args: any[]) => {}>(base: T): T & SlotMixinConstructor;
|
|
11
|
-
|
|
12
|
-
interface SlotMixinConstructor {
|
|
13
|
-
new (...args: any[]): SlotMixin;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface SlotMixin {
|
|
17
|
-
/**
|
|
18
|
-
* List of named slots to initialize.
|
|
19
|
-
*/
|
|
20
|
-
readonly slots: Record<string, () => HTMLElement>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { SlotMixinConstructor, SlotMixin };
|
package/src/slot-mixin.js
DELETED
|
@@ -1,55 +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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
|
|
8
|
-
const SlotMixinImplementation = (superclass) =>
|
|
9
|
-
class SlotMixinClass extends superclass {
|
|
10
|
-
/**
|
|
11
|
-
* List of named slots to initialize.
|
|
12
|
-
*/
|
|
13
|
-
get slots() {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** @protected */
|
|
18
|
-
connectedCallback() {
|
|
19
|
-
super.connectedCallback();
|
|
20
|
-
this._connectSlotMixin();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** @private */
|
|
24
|
-
_connectSlotMixin() {
|
|
25
|
-
if (this.__isConnectedSlotMixin) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Object.keys(this.slots).forEach((slotName) => {
|
|
30
|
-
// Ignore labels of nested components, if any
|
|
31
|
-
const hasContent = this._getDirectSlotChild(slotName) !== undefined;
|
|
32
|
-
|
|
33
|
-
if (!hasContent) {
|
|
34
|
-
const slotFactory = this.slots[slotName];
|
|
35
|
-
const slotContent = slotFactory();
|
|
36
|
-
if (slotContent instanceof Element) {
|
|
37
|
-
slotContent.setAttribute('slot', slotName);
|
|
38
|
-
this.appendChild(slotContent);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
this.__isConnectedSlotMixin = true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** @protected */
|
|
47
|
-
_getDirectSlotChild(slotName) {
|
|
48
|
-
return Array.from(this.children).find((el) => el.slot === slotName);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A mixin to provide content for named slots defined by component.
|
|
54
|
-
*/
|
|
55
|
-
export const SlotMixin = dedupingMixin(SlotMixinImplementation);
|
package/src/tabindex-mixin.d.ts
DELETED
|
@@ -1,29 +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 { DisabledMixin } from './disabled-mixin.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin to provide the `tabindex` attribute.
|
|
10
|
-
*
|
|
11
|
-
* By default, the attribute is set to 0 that makes the element focusable.
|
|
12
|
-
*
|
|
13
|
-
* The attribute is removed whenever the user disables the element
|
|
14
|
-
* and restored with the last known value once the element is enabled again.
|
|
15
|
-
*/
|
|
16
|
-
declare function TabindexMixin<T extends new (...args: any[]) => {}>(base: T): T & TabindexMixinConstructor;
|
|
17
|
-
|
|
18
|
-
interface TabindexMixinConstructor {
|
|
19
|
-
new (...args: any[]): TabindexMixin;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface TabindexMixin extends DisabledMixin {
|
|
23
|
-
/**
|
|
24
|
-
* Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
|
|
25
|
-
*/
|
|
26
|
-
tabindex: number | undefined | null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { TabindexMixinConstructor, TabindexMixin };
|