@momentum-design/components 0.18.5 → 0.18.6
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/dist/browser/index.js +294 -117
- package/dist/browser/index.js.map +4 -4
- package/dist/components/formfieldwrapper/formfieldwrapper.constants.d.ts +3 -3
- package/dist/components/formfieldwrapper/formfieldwrapper.constants.js +3 -3
- package/dist/components/formfieldwrapper/formfieldwrapper.utils.js +4 -4
- package/dist/components/input/index.d.ts +10 -0
- package/dist/components/input/index.js +7 -0
- package/dist/components/input/input.component.d.ts +208 -0
- package/dist/components/input/input.component.js +401 -0
- package/dist/components/input/input.constants.d.ts +25 -0
- package/dist/components/input/input.constants.js +29 -0
- package/dist/components/input/input.styles.d.ts +2 -0
- package/dist/components/input/input.styles.js +118 -0
- package/dist/components/input/input.types.d.ts +4 -0
- package/dist/components/input/input.types.js +1 -0
- package/dist/custom-elements.json +1091 -281
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +3 -2
- package/dist/react/input/index.d.ts +39 -0
- package/dist/react/input/index.js +48 -0
- package/package.json +1 -1
@@ -1,10 +1,10 @@
|
|
1
1
|
declare const TAG_NAME: "mdc-formfieldwrapper";
|
2
2
|
declare const VALIDATION: {
|
3
|
+
readonly DEFAULT: "default";
|
3
4
|
readonly ERROR: "error";
|
4
|
-
readonly WARNING: "warning";
|
5
|
-
readonly SUCCESS: "success";
|
6
5
|
readonly PRIORITY: "priority";
|
7
|
-
readonly
|
6
|
+
readonly SUCCESS: "success";
|
7
|
+
readonly WARNING: "warning";
|
8
8
|
};
|
9
9
|
declare const DEFAULTS: {
|
10
10
|
readonly VALIDATION: "default";
|
@@ -2,11 +2,11 @@ import utils from '../../utils/tag-name';
|
|
2
2
|
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
3
3
|
const TAG_NAME = utils.constructTagName('formfieldwrapper');
|
4
4
|
const VALIDATION = {
|
5
|
+
DEFAULT: 'default',
|
5
6
|
ERROR: 'error',
|
6
|
-
WARNING: 'warning',
|
7
|
-
SUCCESS: 'success',
|
8
7
|
PRIORITY: 'priority',
|
9
|
-
|
8
|
+
SUCCESS: 'success',
|
9
|
+
WARNING: 'warning',
|
10
10
|
};
|
11
11
|
const DEFAULTS = {
|
12
12
|
VALIDATION: VALIDATION.DEFAULT,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { VALIDATION } from './formfieldwrapper.constants';
|
2
2
|
const getHelperIcon = (type) => {
|
3
3
|
const helperIconSizeMap = {
|
4
|
-
[VALIDATION.ERROR]: 'error-legacy-filled',
|
5
|
-
[VALIDATION.WARNING]: 'warning-filled',
|
6
|
-
[VALIDATION.SUCCESS]: 'check-circle-filled',
|
7
|
-
[VALIDATION.PRIORITY]: 'priority-
|
4
|
+
[VALIDATION.ERROR]: 'error-legacy-badge-filled',
|
5
|
+
[VALIDATION.WARNING]: 'warning-badge-filled',
|
6
|
+
[VALIDATION.SUCCESS]: 'check-circle-badge-filled',
|
7
|
+
[VALIDATION.PRIORITY]: 'priority-badge-filled',
|
8
8
|
[VALIDATION.DEFAULT]: '',
|
9
9
|
};
|
10
10
|
return helperIconSizeMap[type] || '';
|
@@ -0,0 +1,208 @@
|
|
1
|
+
import { CSSResult, nothing, PropertyValueMap } from 'lit';
|
2
|
+
import FormfieldWrapper from '../formfieldwrapper';
|
3
|
+
import type { IconNames } from '../icon/icon.types';
|
4
|
+
import type { AutoCapitalizeType } from './input.types';
|
5
|
+
declare const Input_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/ValueMixin").ValueMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/NameMixin").NameMixinInterface> & typeof FormfieldWrapper;
|
6
|
+
/**
|
7
|
+
* mdc-input is a component that allows users to input text.
|
8
|
+
* It contains:
|
9
|
+
* - label field - describe the input field.
|
10
|
+
* - input field - contains the value
|
11
|
+
* - help text or validation message - displayed below the input field.
|
12
|
+
* - trailing button - it displays a clear the input field.
|
13
|
+
* - prefix text - displayed before the input field.
|
14
|
+
* - leading icon - displayed before the input field.
|
15
|
+
* - clear-aria-label - aria label for the trailing button.
|
16
|
+
* - all the attributes of the input field.
|
17
|
+
*
|
18
|
+
* @tagname mdc-input
|
19
|
+
*
|
20
|
+
* @dependency mdc-icon
|
21
|
+
* @dependency mdc-text
|
22
|
+
* @dependency mdc-button
|
23
|
+
*
|
24
|
+
* @cssproperty --mdc-input-disabled-border-color - Border color for the input container when disabled
|
25
|
+
* @cssproperty --mdc-input-disabled-text-color - Text color for the input field when disabled
|
26
|
+
* @cssproperty --mdc-input-disabled-background-color - Background color for the input field when disabled
|
27
|
+
* @cssproperty --mdc-input-border-color - Border color for the input container
|
28
|
+
* @cssproperty --mdc-input-text-color - Text color for the input field
|
29
|
+
* @cssproperty --mdc-input-background-color - Background color for the input field
|
30
|
+
* @cssproperty --mdc-input-selection-background-color - Background color for the selected text
|
31
|
+
* @cssproperty --mdc-input-selection-text-color - Text color for the selected text
|
32
|
+
* @cssproperty --mdc-input-support-text-color - Text color for the help text
|
33
|
+
* @cssproperty --mdc-input-hover-background-color - Background color for the input field when hovered
|
34
|
+
* @cssproperty --mdc-input-focused-background-color - Background color for the input field when focused
|
35
|
+
* @cssproperty --mdc-input-focused-border-color - Border color for the input container when focused
|
36
|
+
* @cssproperty --mdc-input-error-border-color - Border color for the input container when error
|
37
|
+
* @cssproperty --mdc-input-warning-border-color - Border color for the input container when warning
|
38
|
+
* @cssproperty --mdc-input-success-border-color - Border color for the input container when success
|
39
|
+
* @cssproperty --mdc-input-primary-border-color - Border color for the input container when primary
|
40
|
+
*
|
41
|
+
*/
|
42
|
+
declare class Input extends Input_base {
|
43
|
+
/**
|
44
|
+
* The placeholder text that is displayed when the input field is empty.
|
45
|
+
*/
|
46
|
+
placeholder: string;
|
47
|
+
/**
|
48
|
+
* required attribute of the input field.
|
49
|
+
* If true, the consumer should indicate it on the label that the input field is required.
|
50
|
+
*/
|
51
|
+
required: boolean;
|
52
|
+
/**
|
53
|
+
* readonly attribute of the input field. If true, the input field is read-only.
|
54
|
+
*/
|
55
|
+
readonly: boolean;
|
56
|
+
/**
|
57
|
+
* The prefix text that is displayed before the input field. It has a max length of 10 characters.
|
58
|
+
* When the prefix text is set, make sure to set the 'data-aria-label'
|
59
|
+
* attribute with the appropriate value for accessibility.
|
60
|
+
*/
|
61
|
+
prefixText?: string;
|
62
|
+
/**
|
63
|
+
* The leading icon that is displayed before the input field.
|
64
|
+
*/
|
65
|
+
leadingIcon?: IconNames;
|
66
|
+
/**
|
67
|
+
* The trailing button when set to true, shows a clear button that clears the input field.
|
68
|
+
* @default false
|
69
|
+
*/
|
70
|
+
trailingButton: boolean;
|
71
|
+
/**
|
72
|
+
* The maximum number of characters that the input field can accept.
|
73
|
+
*/
|
74
|
+
maxlength?: number;
|
75
|
+
/**
|
76
|
+
* The minimum number of characters that the input field can accept.
|
77
|
+
*/
|
78
|
+
minlength?: number;
|
79
|
+
/**
|
80
|
+
* The autocapitalize attribute of the input field.
|
81
|
+
* @default 'off'
|
82
|
+
*/
|
83
|
+
autocapitalize: AutoCapitalizeType;
|
84
|
+
/**
|
85
|
+
* The autocomplete attribute of the input field.
|
86
|
+
* @default 'off'
|
87
|
+
*/
|
88
|
+
autocomplete: any;
|
89
|
+
/**
|
90
|
+
* If true, the input field is focused when the component is rendered.
|
91
|
+
* @default false
|
92
|
+
*/
|
93
|
+
autofocus: boolean;
|
94
|
+
/**
|
95
|
+
* Specifies the name of the directionality of text for submission purposes (e.g., "rtl" for right-to-left).
|
96
|
+
*/
|
97
|
+
dirname?: string;
|
98
|
+
/**
|
99
|
+
* The pattern attribute of the input field.
|
100
|
+
* Specifies a regular expression that the input value must match for validation purposes.
|
101
|
+
*/
|
102
|
+
pattern?: string;
|
103
|
+
/**
|
104
|
+
* The list attribute of the input field.
|
105
|
+
* Identifies a list of pre-defined options to suggest to the user.
|
106
|
+
*/
|
107
|
+
list?: string;
|
108
|
+
/**
|
109
|
+
* The size attribute of the input field.
|
110
|
+
* Specifies the width of the input field.
|
111
|
+
* @default undefined
|
112
|
+
*/
|
113
|
+
size?: number | undefined;
|
114
|
+
/**
|
115
|
+
* Aria label for the trailing button. If trailing button is set to true, this label is used for the clear button.
|
116
|
+
* @default ''
|
117
|
+
*/
|
118
|
+
clearAriaLabel: string;
|
119
|
+
checkValidity(): boolean;
|
120
|
+
reportValidity(): boolean;
|
121
|
+
/** @internal */
|
122
|
+
private internals;
|
123
|
+
/** @internal */
|
124
|
+
static formAssociated: boolean;
|
125
|
+
/** @internal */
|
126
|
+
get form(): HTMLFormElement | null;
|
127
|
+
constructor();
|
128
|
+
/**
|
129
|
+
* @internal
|
130
|
+
* The input element
|
131
|
+
*/
|
132
|
+
private inputElement;
|
133
|
+
connectedCallback(): void;
|
134
|
+
protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
135
|
+
/**
|
136
|
+
* Handles the value change of the input field.
|
137
|
+
* Sets the form value and updates the validity of the input field.
|
138
|
+
* @returns void
|
139
|
+
*/
|
140
|
+
handleValueChange(): void;
|
141
|
+
/**
|
142
|
+
* This function is called when the attribute changes.
|
143
|
+
* It updates the validity of the input field based on the input field's validity.
|
144
|
+
*
|
145
|
+
* @param name - attribute name
|
146
|
+
* @param old - old value
|
147
|
+
* @param value - new value
|
148
|
+
*/
|
149
|
+
attributeChangedCallback(name: string, old: string | null, value: string | null): void;
|
150
|
+
/**
|
151
|
+
* Sets the validity of the input field based on the input field's validity.
|
152
|
+
* @returns void
|
153
|
+
*/
|
154
|
+
private setValidityFromInput;
|
155
|
+
/**
|
156
|
+
* Updates the value of the input field.
|
157
|
+
* Sets the form value.
|
158
|
+
* @returns void
|
159
|
+
*/
|
160
|
+
private updateValue;
|
161
|
+
/**
|
162
|
+
* Handles the input event of the input field.
|
163
|
+
* Updates the value and sets the validity of the input field.
|
164
|
+
*
|
165
|
+
*/
|
166
|
+
private onInput;
|
167
|
+
/**
|
168
|
+
* Handles the change event of the input field.
|
169
|
+
* Updates the value and sets the validity of the input field.
|
170
|
+
*
|
171
|
+
* The 'change' event does not bubble up through the shadow DOM as it was not composed.
|
172
|
+
* Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
|
173
|
+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
|
174
|
+
*
|
175
|
+
* @param event - Event which contains information about the value change.
|
176
|
+
*/
|
177
|
+
private onChange;
|
178
|
+
/**
|
179
|
+
* Renders the leading icon before the input field.
|
180
|
+
* If the leading icon is not set, it will not be displayed.
|
181
|
+
*
|
182
|
+
* @returns void
|
183
|
+
*/
|
184
|
+
protected renderLeadingIcon(): import("lit-html").TemplateResult<1> | typeof nothing;
|
185
|
+
/**
|
186
|
+
* Renders the prefix text before the input field.
|
187
|
+
* If the prefix text is more than 10 characters,
|
188
|
+
* - it will not be displayed.
|
189
|
+
* - the validation messsage will be displayed.
|
190
|
+
*
|
191
|
+
* Note: We are setting aria-hidden so that the screen reader does not read the prefix text.
|
192
|
+
* The consumers should set the appropriate aria-label for the input field using 'data-aria-label' attribute.
|
193
|
+
* @returns void
|
194
|
+
*/
|
195
|
+
protected renderPrefixText(): import("lit-html").TemplateResult<1> | typeof nothing;
|
196
|
+
/**
|
197
|
+
* Clears the input field.
|
198
|
+
*/
|
199
|
+
private clearInputText;
|
200
|
+
/**
|
201
|
+
* Renders the trailing button to clear the input field if the trailingButton is set to true.
|
202
|
+
* @returns void
|
203
|
+
*/
|
204
|
+
protected renderTrailingButton(): import("lit-html").TemplateResult<1> | typeof nothing;
|
205
|
+
render(): import("lit-html").TemplateResult<1>;
|
206
|
+
static styles: Array<CSSResult>;
|
207
|
+
}
|
208
|
+
export default Input;
|
@@ -0,0 +1,401 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html, nothing } from 'lit';
|
11
|
+
import { property, query } from 'lit/decorators.js';
|
12
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
|
+
import styles from './input.styles';
|
14
|
+
import FormfieldWrapper from '../formfieldwrapper';
|
15
|
+
import { NameMixin } from '../../utils/mixins/NameMixin';
|
16
|
+
import { AUTO_CAPITALIZE, DEFAULTS, PREFIX_TEXT_OPTIONS } from './input.constants';
|
17
|
+
import { ValueMixin } from '../../utils/mixins/ValueMixin';
|
18
|
+
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
19
|
+
/**
|
20
|
+
* mdc-input is a component that allows users to input text.
|
21
|
+
* It contains:
|
22
|
+
* - label field - describe the input field.
|
23
|
+
* - input field - contains the value
|
24
|
+
* - help text or validation message - displayed below the input field.
|
25
|
+
* - trailing button - it displays a clear the input field.
|
26
|
+
* - prefix text - displayed before the input field.
|
27
|
+
* - leading icon - displayed before the input field.
|
28
|
+
* - clear-aria-label - aria label for the trailing button.
|
29
|
+
* - all the attributes of the input field.
|
30
|
+
*
|
31
|
+
* @tagname mdc-input
|
32
|
+
*
|
33
|
+
* @dependency mdc-icon
|
34
|
+
* @dependency mdc-text
|
35
|
+
* @dependency mdc-button
|
36
|
+
*
|
37
|
+
* @cssproperty --mdc-input-disabled-border-color - Border color for the input container when disabled
|
38
|
+
* @cssproperty --mdc-input-disabled-text-color - Text color for the input field when disabled
|
39
|
+
* @cssproperty --mdc-input-disabled-background-color - Background color for the input field when disabled
|
40
|
+
* @cssproperty --mdc-input-border-color - Border color for the input container
|
41
|
+
* @cssproperty --mdc-input-text-color - Text color for the input field
|
42
|
+
* @cssproperty --mdc-input-background-color - Background color for the input field
|
43
|
+
* @cssproperty --mdc-input-selection-background-color - Background color for the selected text
|
44
|
+
* @cssproperty --mdc-input-selection-text-color - Text color for the selected text
|
45
|
+
* @cssproperty --mdc-input-support-text-color - Text color for the help text
|
46
|
+
* @cssproperty --mdc-input-hover-background-color - Background color for the input field when hovered
|
47
|
+
* @cssproperty --mdc-input-focused-background-color - Background color for the input field when focused
|
48
|
+
* @cssproperty --mdc-input-focused-border-color - Border color for the input container when focused
|
49
|
+
* @cssproperty --mdc-input-error-border-color - Border color for the input container when error
|
50
|
+
* @cssproperty --mdc-input-warning-border-color - Border color for the input container when warning
|
51
|
+
* @cssproperty --mdc-input-success-border-color - Border color for the input container when success
|
52
|
+
* @cssproperty --mdc-input-primary-border-color - Border color for the input container when primary
|
53
|
+
*
|
54
|
+
*/
|
55
|
+
class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper))) {
|
56
|
+
checkValidity() {
|
57
|
+
this.setValidityFromInput();
|
58
|
+
return this.internals.checkValidity();
|
59
|
+
}
|
60
|
+
reportValidity() {
|
61
|
+
this.setValidityFromInput();
|
62
|
+
return this.internals.reportValidity();
|
63
|
+
}
|
64
|
+
/** @internal */
|
65
|
+
get form() {
|
66
|
+
return this.internals.form;
|
67
|
+
}
|
68
|
+
constructor() {
|
69
|
+
super();
|
70
|
+
/**
|
71
|
+
* The placeholder text that is displayed when the input field is empty.
|
72
|
+
*/
|
73
|
+
this.placeholder = '';
|
74
|
+
/**
|
75
|
+
* required attribute of the input field.
|
76
|
+
* If true, the consumer should indicate it on the label that the input field is required.
|
77
|
+
*/
|
78
|
+
this.required = false;
|
79
|
+
/**
|
80
|
+
* readonly attribute of the input field. If true, the input field is read-only.
|
81
|
+
*/
|
82
|
+
this.readonly = false;
|
83
|
+
/**
|
84
|
+
* The trailing button when set to true, shows a clear button that clears the input field.
|
85
|
+
* @default false
|
86
|
+
*/
|
87
|
+
this.trailingButton = false;
|
88
|
+
/**
|
89
|
+
* The autocapitalize attribute of the input field.
|
90
|
+
* @default 'off'
|
91
|
+
*/
|
92
|
+
this.autocapitalize = AUTO_CAPITALIZE.OFF;
|
93
|
+
/**
|
94
|
+
* The autocomplete attribute of the input field.
|
95
|
+
* @default 'off'
|
96
|
+
*/
|
97
|
+
this.autocomplete = 'off';
|
98
|
+
/**
|
99
|
+
* If true, the input field is focused when the component is rendered.
|
100
|
+
* @default false
|
101
|
+
*/
|
102
|
+
this.autofocus = false;
|
103
|
+
/**
|
104
|
+
* Aria label for the trailing button. If trailing button is set to true, this label is used for the clear button.
|
105
|
+
* @default ''
|
106
|
+
*/
|
107
|
+
this.clearAriaLabel = '';
|
108
|
+
/** @internal */
|
109
|
+
this.internals = this.attachInternals();
|
110
|
+
}
|
111
|
+
connectedCallback() {
|
112
|
+
super.connectedCallback();
|
113
|
+
this.updateComplete.then(() => {
|
114
|
+
if (this.inputElement) {
|
115
|
+
this.inputElement.checkValidity();
|
116
|
+
this.setValidityFromInput();
|
117
|
+
this.internals.setFormValue(this.inputElement.value);
|
118
|
+
}
|
119
|
+
}).catch((error) => {
|
120
|
+
if (this.onerror) {
|
121
|
+
this.onerror(error);
|
122
|
+
}
|
123
|
+
});
|
124
|
+
}
|
125
|
+
updated(changedProperties) {
|
126
|
+
super.updated(changedProperties);
|
127
|
+
if (changedProperties.has('value')) {
|
128
|
+
this.handleValueChange();
|
129
|
+
}
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Handles the value change of the input field.
|
133
|
+
* Sets the form value and updates the validity of the input field.
|
134
|
+
* @returns void
|
135
|
+
*/
|
136
|
+
handleValueChange() {
|
137
|
+
this.internals.setFormValue(this.value);
|
138
|
+
this.updateComplete.then(() => {
|
139
|
+
this.setValidityFromInput();
|
140
|
+
}).catch((error) => {
|
141
|
+
if (this.onerror) {
|
142
|
+
this.onerror(error);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* This function is called when the attribute changes.
|
148
|
+
* It updates the validity of the input field based on the input field's validity.
|
149
|
+
*
|
150
|
+
* @param name - attribute name
|
151
|
+
* @param old - old value
|
152
|
+
* @param value - new value
|
153
|
+
*/
|
154
|
+
attributeChangedCallback(name, old, value) {
|
155
|
+
super.attributeChangedCallback(name, old, value);
|
156
|
+
const validationRelatedAttributes = [
|
157
|
+
'maxlength',
|
158
|
+
'minlength',
|
159
|
+
'pattern',
|
160
|
+
'required',
|
161
|
+
];
|
162
|
+
if (validationRelatedAttributes.includes(name)) {
|
163
|
+
this.updateComplete.then(() => {
|
164
|
+
this.setValidityFromInput();
|
165
|
+
}).catch((error) => {
|
166
|
+
if (this.onerror) {
|
167
|
+
this.onerror(error);
|
168
|
+
}
|
169
|
+
});
|
170
|
+
}
|
171
|
+
}
|
172
|
+
/**
|
173
|
+
* Sets the validity of the input field based on the input field's validity.
|
174
|
+
* @returns void
|
175
|
+
*/
|
176
|
+
setValidityFromInput() {
|
177
|
+
if (this.inputElement) {
|
178
|
+
this.internals.setValidity(this.inputElement.validity, this.inputElement.validationMessage, this.inputElement);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
/**
|
182
|
+
* Updates the value of the input field.
|
183
|
+
* Sets the form value.
|
184
|
+
* @returns void
|
185
|
+
*/
|
186
|
+
updateValue() {
|
187
|
+
this.value = this.inputElement.value;
|
188
|
+
this.internals.setFormValue(this.inputElement.value);
|
189
|
+
}
|
190
|
+
/**
|
191
|
+
* Handles the input event of the input field.
|
192
|
+
* Updates the value and sets the validity of the input field.
|
193
|
+
*
|
194
|
+
*/
|
195
|
+
onInput() {
|
196
|
+
this.updateValue();
|
197
|
+
this.setValidityFromInput();
|
198
|
+
}
|
199
|
+
/**
|
200
|
+
* Handles the change event of the input field.
|
201
|
+
* Updates the value and sets the validity of the input field.
|
202
|
+
*
|
203
|
+
* The 'change' event does not bubble up through the shadow DOM as it was not composed.
|
204
|
+
* Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
|
205
|
+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
|
206
|
+
*
|
207
|
+
* @param event - Event which contains information about the value change.
|
208
|
+
*/
|
209
|
+
onChange(event) {
|
210
|
+
this.updateValue();
|
211
|
+
this.setValidityFromInput();
|
212
|
+
const EventConstructor = event.constructor;
|
213
|
+
this.dispatchEvent(new EventConstructor(event.type, event));
|
214
|
+
}
|
215
|
+
/**
|
216
|
+
* Renders the leading icon before the input field.
|
217
|
+
* If the leading icon is not set, it will not be displayed.
|
218
|
+
*
|
219
|
+
* @returns void
|
220
|
+
*/
|
221
|
+
renderLeadingIcon() {
|
222
|
+
if (!this.leadingIcon) {
|
223
|
+
return nothing;
|
224
|
+
}
|
225
|
+
return html `
|
226
|
+
<mdc-icon
|
227
|
+
class="leading-icon"
|
228
|
+
part="leading-icon"
|
229
|
+
name=${this.leadingIcon}
|
230
|
+
size="${DEFAULTS.ICON_SIZE_VALUE}"
|
231
|
+
length-unit="${DEFAULTS.ICON_SIZE_UNIT}">
|
232
|
+
</mdc-icon>
|
233
|
+
`;
|
234
|
+
}
|
235
|
+
/**
|
236
|
+
* Renders the prefix text before the input field.
|
237
|
+
* If the prefix text is more than 10 characters,
|
238
|
+
* - it will not be displayed.
|
239
|
+
* - the validation messsage will be displayed.
|
240
|
+
*
|
241
|
+
* Note: We are setting aria-hidden so that the screen reader does not read the prefix text.
|
242
|
+
* The consumers should set the appropriate aria-label for the input field using 'data-aria-label' attribute.
|
243
|
+
* @returns void
|
244
|
+
*/
|
245
|
+
renderPrefixText() {
|
246
|
+
if (!this.prefixText) {
|
247
|
+
return nothing;
|
248
|
+
}
|
249
|
+
return html `
|
250
|
+
<mdc-text
|
251
|
+
class="prefix-text"
|
252
|
+
tagname="${DEFAULTS.PREFIX_TEXT_TAG}"
|
253
|
+
type="${DEFAULTS.PREFIX_TEXT_TYPE}"
|
254
|
+
aria-hidden="true"
|
255
|
+
>
|
256
|
+
${this.prefixText.slice(0, PREFIX_TEXT_OPTIONS.MAX_LENGTH)}
|
257
|
+
</mdc-text>
|
258
|
+
`;
|
259
|
+
}
|
260
|
+
/**
|
261
|
+
* Clears the input field.
|
262
|
+
*/
|
263
|
+
clearInputText() {
|
264
|
+
var _a;
|
265
|
+
this.value = '';
|
266
|
+
// focus the input field after clearing the text
|
267
|
+
(_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.focus();
|
268
|
+
}
|
269
|
+
/**
|
270
|
+
* Renders the trailing button to clear the input field if the trailingButton is set to true.
|
271
|
+
* @returns void
|
272
|
+
*/
|
273
|
+
renderTrailingButton() {
|
274
|
+
if (!this.trailingButton) {
|
275
|
+
return nothing;
|
276
|
+
}
|
277
|
+
return html `
|
278
|
+
<mdc-button
|
279
|
+
class='${!this.value ? 'hidden' : ''}'
|
280
|
+
prefix-icon='${DEFAULTS.CLEAR_BUTTON_ICON}'
|
281
|
+
variant='${DEFAULTS.CLEAR_BUTTON_VARIANT}'
|
282
|
+
size="${DEFAULTS.CLEAR_BUTTON_SIZE}"
|
283
|
+
aria-label="${this.clearAriaLabel}"
|
284
|
+
@click=${this.clearInputText}
|
285
|
+
?disabled=${this.disabled || this.readonly || !this.value}
|
286
|
+
></mdc-button>
|
287
|
+
`;
|
288
|
+
}
|
289
|
+
render() {
|
290
|
+
var _a;
|
291
|
+
return html `
|
292
|
+
${this.renderLabel()}
|
293
|
+
<div class="input-container mdc-focus-ring" part="input-container">
|
294
|
+
<slot name="input-leading-icon">${this.renderLeadingIcon()}</slot>
|
295
|
+
<div class="input-section" part="input-section">
|
296
|
+
<slot name="input-prefix-text">${this.renderPrefixText()}</slot>
|
297
|
+
<slot name="input">
|
298
|
+
<input
|
299
|
+
aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
|
300
|
+
class='input'
|
301
|
+
part='input'
|
302
|
+
id="${this.id}"
|
303
|
+
name="${this.name}"
|
304
|
+
.value="${this.value}"
|
305
|
+
?disabled="${this.disabled}"
|
306
|
+
?readonly="${this.readonly}"
|
307
|
+
?required="${this.required}"
|
308
|
+
type="text"
|
309
|
+
placeholder=${ifDefined(this.placeholder)}
|
310
|
+
minlength=${ifDefined(this.minlength)}
|
311
|
+
maxlength=${ifDefined(this.maxlength)}
|
312
|
+
autocapitalize=${this.autocapitalize}
|
313
|
+
autocomplete=${this.autocomplete}
|
314
|
+
?autofocus="${this.autofocus}"
|
315
|
+
dirname=${ifDefined(this.dirname)}
|
316
|
+
pattern=${ifDefined(this.pattern)}
|
317
|
+
list=${ifDefined(this.list)}
|
318
|
+
size=${ifDefined(this.size)}
|
319
|
+
@input=${this.onInput}
|
320
|
+
@change=${this.onChange}
|
321
|
+
/>
|
322
|
+
</slot>
|
323
|
+
</div>
|
324
|
+
<slot name="trailing-button">${this.renderTrailingButton()}</slot>
|
325
|
+
</div>
|
326
|
+
${this.helpText ? this.renderHelperText() : nothing}
|
327
|
+
`;
|
328
|
+
}
|
329
|
+
}
|
330
|
+
/** @internal */
|
331
|
+
Input.formAssociated = true;
|
332
|
+
Input.styles = [...FormfieldWrapper.styles, ...styles];
|
333
|
+
__decorate([
|
334
|
+
property({ type: String }),
|
335
|
+
__metadata("design:type", Object)
|
336
|
+
], Input.prototype, "placeholder", void 0);
|
337
|
+
__decorate([
|
338
|
+
property({ type: Boolean }),
|
339
|
+
__metadata("design:type", Object)
|
340
|
+
], Input.prototype, "required", void 0);
|
341
|
+
__decorate([
|
342
|
+
property({ type: Boolean }),
|
343
|
+
__metadata("design:type", Object)
|
344
|
+
], Input.prototype, "readonly", void 0);
|
345
|
+
__decorate([
|
346
|
+
property({ type: String, attribute: 'prefix-text' }),
|
347
|
+
__metadata("design:type", String)
|
348
|
+
], Input.prototype, "prefixText", void 0);
|
349
|
+
__decorate([
|
350
|
+
property({ type: String, attribute: 'leading-icon' }),
|
351
|
+
__metadata("design:type", String)
|
352
|
+
], Input.prototype, "leadingIcon", void 0);
|
353
|
+
__decorate([
|
354
|
+
property({ type: Boolean, attribute: 'trailing-button' }),
|
355
|
+
__metadata("design:type", Object)
|
356
|
+
], Input.prototype, "trailingButton", void 0);
|
357
|
+
__decorate([
|
358
|
+
property({ type: Number }),
|
359
|
+
__metadata("design:type", Number)
|
360
|
+
], Input.prototype, "maxlength", void 0);
|
361
|
+
__decorate([
|
362
|
+
property({ type: Number }),
|
363
|
+
__metadata("design:type", Number)
|
364
|
+
], Input.prototype, "minlength", void 0);
|
365
|
+
__decorate([
|
366
|
+
property({ type: String }),
|
367
|
+
__metadata("design:type", String)
|
368
|
+
], Input.prototype, "autocapitalize", void 0);
|
369
|
+
__decorate([
|
370
|
+
property({ type: String }),
|
371
|
+
__metadata("design:type", Object)
|
372
|
+
], Input.prototype, "autocomplete", void 0);
|
373
|
+
__decorate([
|
374
|
+
property({ type: Boolean }),
|
375
|
+
__metadata("design:type", Object)
|
376
|
+
], Input.prototype, "autofocus", void 0);
|
377
|
+
__decorate([
|
378
|
+
property({ type: String }),
|
379
|
+
__metadata("design:type", String)
|
380
|
+
], Input.prototype, "dirname", void 0);
|
381
|
+
__decorate([
|
382
|
+
property({ type: String }),
|
383
|
+
__metadata("design:type", String)
|
384
|
+
], Input.prototype, "pattern", void 0);
|
385
|
+
__decorate([
|
386
|
+
property({ type: String }),
|
387
|
+
__metadata("design:type", String)
|
388
|
+
], Input.prototype, "list", void 0);
|
389
|
+
__decorate([
|
390
|
+
property({ type: Number }),
|
391
|
+
__metadata("design:type", Object)
|
392
|
+
], Input.prototype, "size", void 0);
|
393
|
+
__decorate([
|
394
|
+
property({ type: String, attribute: 'clear-aria-label' }),
|
395
|
+
__metadata("design:type", Object)
|
396
|
+
], Input.prototype, "clearAriaLabel", void 0);
|
397
|
+
__decorate([
|
398
|
+
query('input'),
|
399
|
+
__metadata("design:type", HTMLInputElement)
|
400
|
+
], Input.prototype, "inputElement", void 0);
|
401
|
+
export default Input;
|