@momentum-design/components 0.32.0 → 0.32.1
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 +313 -140
- package/dist/browser/index.js.map +4 -4
- package/dist/components/input/input.component.js +1 -1
- package/dist/components/textarea/index.d.ts +10 -0
- package/dist/components/textarea/index.js +7 -0
- package/dist/components/textarea/textarea.component.d.ts +203 -0
- package/dist/components/textarea/textarea.component.js +432 -0
- package/dist/components/textarea/textarea.constants.d.ts +21 -0
- package/dist/components/textarea/textarea.constants.js +25 -0
- package/dist/components/textarea/textarea.styles.d.ts +2 -0
- package/dist/components/textarea/textarea.styles.js +122 -0
- package/dist/components/textarea/textarea.types.d.ts +5 -0
- package/dist/components/textarea/textarea.types.js +1 -0
- package/dist/custom-elements.json +1515 -579
- 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/textarea/index.d.ts +61 -0
- package/dist/react/textarea/index.js +70 -0
- package/dist/utils/mixins/FormInternalsMixin.d.ts +2 -2
- package/dist/utils/mixins/FormInternalsMixin.js +1 -1
- package/package.json +1 -1
@@ -138,7 +138,7 @@ class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
|
|
138
138
|
}
|
139
139
|
}
|
140
140
|
setInputValidity() {
|
141
|
-
if (this.validationMessage && this.value === '') {
|
141
|
+
if (this.requiredLabel && this.validationMessage && this.value === '') {
|
142
142
|
this.inputElement.setCustomValidity(this.validationMessage);
|
143
143
|
}
|
144
144
|
else {
|
@@ -0,0 +1,203 @@
|
|
1
|
+
import { CSSResult, nothing, PropertyValueMap } from 'lit';
|
2
|
+
import FormfieldWrapper from '../formfieldwrapper';
|
3
|
+
import type { AutoCapitalizeType } from '../input/input.types';
|
4
|
+
import type { WrapType, AutoCompleteType } from './textarea.types';
|
5
|
+
declare const Textarea_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/FormInternalsMixin").FormInternalsMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
|
6
|
+
/**
|
7
|
+
* mdc-textarea component, which is used to get the multi-line text input from the user.
|
8
|
+
* It contains:
|
9
|
+
* - label: It is the title of the textarea field.
|
10
|
+
* - required-label: A string depicting that the textarea field is required.
|
11
|
+
* - Textarea: It is the multi-line text input field.
|
12
|
+
* - helper-text: It is the text that provides additional information about the textarea field.
|
13
|
+
* - max-character-limit: It is the text that shows the character count of the textarea field.
|
14
|
+
* - clear-button: A boolean value when marked to true represents a button that can
|
15
|
+
* clear the text value within the textarea field.
|
16
|
+
* - Error, Warning, Success, Priority Help Text type: It is the text that provides additional information
|
17
|
+
* about the textarea field based on the validation state.
|
18
|
+
* - limitexceeded: It is the event that is dispatched when the character limit exceeds or restored.
|
19
|
+
* This event exposes 3 properties:
|
20
|
+
* - currentCharacterCount - the current number of characters in the textarea field,
|
21
|
+
* - maxCharacterLimit - the maximum number of characters allowed in the textarea field,
|
22
|
+
* - value - the current value of the textarea field,
|
23
|
+
*
|
24
|
+
* **Note**: Consumers must set the help-text-type with 'error' and
|
25
|
+
* help-text attribute with the error message using limitexceeded event.
|
26
|
+
* The same help-text value will be used for the validation message to be displayed.
|
27
|
+
*
|
28
|
+
* @tagname mdc-textarea
|
29
|
+
*
|
30
|
+
* @event input - (React: onInput) This event is dispatched when the value of the textarea field changes (every press).
|
31
|
+
* @event change - (React: onChange) This event is dispatched when the value of the textarea field changes (on blur).
|
32
|
+
* @event focus - (React: onFocus) This event is dispatched when the textarea receives focus.
|
33
|
+
* @event blur - (React: onBlur) This event is dispatched when the textarea loses focus.
|
34
|
+
* @event limitexceeded - (React: onLimitExceeded) This event is dispatched once when the character limit
|
35
|
+
* exceeds or restored.
|
36
|
+
*
|
37
|
+
*
|
38
|
+
* @dependency mdc-icon
|
39
|
+
* @dependency mdc-text
|
40
|
+
* @dependency mdc-button
|
41
|
+
*
|
42
|
+
* @cssproperty --mdc-textarea-disabled-border-color - Border color for the textarea container when disabled
|
43
|
+
* @cssproperty --mdc-textarea-disabled-text-color - Text color for the textarea field when disabled
|
44
|
+
* @cssproperty --mdc-textarea-disabled-background-color - Background color for the textarea field when disabled
|
45
|
+
* @cssproperty --mdc-textarea-text-color - Text color for the textarea field
|
46
|
+
* @cssproperty --mdc-textarea-background-color - Background color for the textarea field
|
47
|
+
* @cssproperty --mdc-textarea-border-color - Border color for the textarea field
|
48
|
+
* @cssproperty --mdc-textarea-text-secondary-normal - Text color for the character counter
|
49
|
+
* @cssproperty --mdc-textarea-error-border-color - Border color for the error related help text
|
50
|
+
* @cssproperty --mdc-textarea-warning-border-color - Border color for the warning related help text
|
51
|
+
* @cssproperty --mdc-textarea-success-border-color - Border color for the success related help text
|
52
|
+
* @cssproperty --mdc-textarea-primary-border-color - Border color for the priority related help text
|
53
|
+
* @cssproperty --mdc-textarea-hover-background-color - Background color for the textarea container when hover
|
54
|
+
* @cssproperty --mdc-textarea-focused-background-color - Background color for the textarea container when focused
|
55
|
+
* @cssproperty --mdc-textarea-focused-border-color - Border color for the textarea container when focused
|
56
|
+
*/
|
57
|
+
declare class Textarea extends Textarea_base {
|
58
|
+
/**
|
59
|
+
* The placeholder text that is displayed when the textarea field is empty.
|
60
|
+
*/
|
61
|
+
placeholder?: string;
|
62
|
+
/**
|
63
|
+
* readonly attribute of the textarea field. If true, the textarea field is read-only.
|
64
|
+
* @default false
|
65
|
+
*/
|
66
|
+
readonly: boolean;
|
67
|
+
/**
|
68
|
+
* The rows attribute specifies the visible number of lines in a text area.
|
69
|
+
* @default 5
|
70
|
+
*/
|
71
|
+
rows: number;
|
72
|
+
/**
|
73
|
+
* The cols attribute specifies the visible number of lines in a text area.
|
74
|
+
* @default 40
|
75
|
+
*/
|
76
|
+
cols: number;
|
77
|
+
/**
|
78
|
+
* The wrap attribute specifies how the text in a text area is to be wrapped when submitted in a form.
|
79
|
+
* @default 'soft'
|
80
|
+
*/
|
81
|
+
wrap: WrapType;
|
82
|
+
/**
|
83
|
+
* The autocapitalize attribute of the textarea field.
|
84
|
+
* @default 'off'
|
85
|
+
*/
|
86
|
+
autocapitalize: AutoCapitalizeType;
|
87
|
+
/**
|
88
|
+
* The autocomplete attribute of the textarea field.
|
89
|
+
* @default 'off'
|
90
|
+
*/
|
91
|
+
autocomplete: AutoCompleteType;
|
92
|
+
/**
|
93
|
+
* If true, the textarea field is focused when the component is rendered.
|
94
|
+
* @default false
|
95
|
+
*/
|
96
|
+
autofocus: boolean;
|
97
|
+
/**
|
98
|
+
* Specifies the name of the directionality of text for submission purposes (e.g., "rtl" for right-to-left).
|
99
|
+
*/
|
100
|
+
dirname?: string;
|
101
|
+
/**
|
102
|
+
* The maximum number of characters that the textarea field can accept.
|
103
|
+
*/
|
104
|
+
maxlength?: number;
|
105
|
+
/**
|
106
|
+
* The minimum number of characters that the textarea field can accept.
|
107
|
+
*/
|
108
|
+
minlength?: number;
|
109
|
+
/**
|
110
|
+
* The clear button when set to true, shows a clear button that clears the textarea field.
|
111
|
+
* @default false
|
112
|
+
*/
|
113
|
+
clearButton: boolean;
|
114
|
+
/**
|
115
|
+
* Aria label for the clear button. If clear button is set to true, this label is used for the clear button.
|
116
|
+
* @default ''
|
117
|
+
*/
|
118
|
+
clearAriaLabel: string;
|
119
|
+
/**
|
120
|
+
* maximum character limit for the textarea field for character counter.
|
121
|
+
*/
|
122
|
+
maxCharacterLimit?: number;
|
123
|
+
/**
|
124
|
+
* @internal
|
125
|
+
* The textarea element
|
126
|
+
*/
|
127
|
+
inputElement: HTMLTextAreaElement;
|
128
|
+
private characterLimitExceedingFired;
|
129
|
+
protected get textarea(): HTMLTextAreaElement;
|
130
|
+
constructor();
|
131
|
+
connectedCallback(): void;
|
132
|
+
private setTextareaValidity;
|
133
|
+
/** @internal */
|
134
|
+
formResetCallback(): void;
|
135
|
+
/** @internal */
|
136
|
+
formStateRestoreCallback(state: string): void;
|
137
|
+
/**
|
138
|
+
* Handles the value change of the textarea field.
|
139
|
+
* Sets the form value and updates the validity of the textarea field.
|
140
|
+
* @returns void
|
141
|
+
*/
|
142
|
+
handleValueChange(): void;
|
143
|
+
protected updated(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
144
|
+
/**
|
145
|
+
* This function is called when the attribute changes.
|
146
|
+
* It updates the validity of the textarea field based on the textarea field's validity.
|
147
|
+
*
|
148
|
+
* @param name - attribute name
|
149
|
+
* @param old - old value
|
150
|
+
* @param value - new value
|
151
|
+
*/
|
152
|
+
attributeChangedCallback(name: string, old: string | null, value: string | null): void;
|
153
|
+
/**
|
154
|
+
* Dispatches the character overflow state change event.
|
155
|
+
* @returns void
|
156
|
+
*/
|
157
|
+
private dispatchCharacterOverflowStateChangeEvent;
|
158
|
+
/**
|
159
|
+
* Handles the character overflow state change.
|
160
|
+
* Dispatches the character overflow state change event if the character limit is exceeded or restored.
|
161
|
+
* @returns void
|
162
|
+
*/
|
163
|
+
private handleCharacterOverflowStateChange;
|
164
|
+
/**
|
165
|
+
* Updates the value of the textarea field.
|
166
|
+
* Sets the form value.
|
167
|
+
* @returns void
|
168
|
+
*/
|
169
|
+
private updateValue;
|
170
|
+
/**
|
171
|
+
* Handles the change event of the textarea field.
|
172
|
+
* Updates the value and sets the validity of the textarea field.
|
173
|
+
*
|
174
|
+
* The 'change' event does not bubble up through the shadow DOM as it was not composed.
|
175
|
+
* Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
|
176
|
+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
|
177
|
+
*
|
178
|
+
* @param event - Event which contains information about the value change.
|
179
|
+
*/
|
180
|
+
private onChange;
|
181
|
+
/**
|
182
|
+
* Handles the keydown event of the textarea field.
|
183
|
+
* Clears the textarea field when the 'Enter' key is pressed.
|
184
|
+
* @param event - Keyboard event
|
185
|
+
* @returns void
|
186
|
+
*/
|
187
|
+
private handleKeyDown;
|
188
|
+
/**
|
189
|
+
* Clears the textarea field.
|
190
|
+
* @returns void
|
191
|
+
*/
|
192
|
+
private clearInputText;
|
193
|
+
/**
|
194
|
+
* Renders the clear button to clear the textarea field if the clearButton is set to true.
|
195
|
+
* @returns void
|
196
|
+
*/
|
197
|
+
protected renderClearButton(): import("lit-html").TemplateResult<1> | typeof nothing;
|
198
|
+
protected renderCharacterCounter(): import("lit-html").TemplateResult<1> | typeof nothing;
|
199
|
+
protected renderTextareaFooter(): import("lit-html").TemplateResult<1> | typeof nothing;
|
200
|
+
render(): import("lit-html").TemplateResult<1>;
|
201
|
+
static styles: Array<CSSResult>;
|
202
|
+
}
|
203
|
+
export default Textarea;
|
@@ -0,0 +1,432 @@
|
|
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 { ifDefined } from 'lit/directives/if-defined.js';
|
12
|
+
import { property, query } from 'lit/decorators.js';
|
13
|
+
import styles from './textarea.styles';
|
14
|
+
import FormfieldWrapper from '../formfieldwrapper';
|
15
|
+
import { DEFAULTS as FORMFIELD_DEFAULTS, VALIDATION } from '../formfieldwrapper/formfieldwrapper.constants';
|
16
|
+
import { AUTO_CAPITALIZE } from '../input/input.constants';
|
17
|
+
import { AUTO_COMPLETE, WRAP, DEFAULTS } from './textarea.constants';
|
18
|
+
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
19
|
+
import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
|
20
|
+
/**
|
21
|
+
* mdc-textarea component, which is used to get the multi-line text input from the user.
|
22
|
+
* It contains:
|
23
|
+
* - label: It is the title of the textarea field.
|
24
|
+
* - required-label: A string depicting that the textarea field is required.
|
25
|
+
* - Textarea: It is the multi-line text input field.
|
26
|
+
* - helper-text: It is the text that provides additional information about the textarea field.
|
27
|
+
* - max-character-limit: It is the text that shows the character count of the textarea field.
|
28
|
+
* - clear-button: A boolean value when marked to true represents a button that can
|
29
|
+
* clear the text value within the textarea field.
|
30
|
+
* - Error, Warning, Success, Priority Help Text type: It is the text that provides additional information
|
31
|
+
* about the textarea field based on the validation state.
|
32
|
+
* - limitexceeded: It is the event that is dispatched when the character limit exceeds or restored.
|
33
|
+
* This event exposes 3 properties:
|
34
|
+
* - currentCharacterCount - the current number of characters in the textarea field,
|
35
|
+
* - maxCharacterLimit - the maximum number of characters allowed in the textarea field,
|
36
|
+
* - value - the current value of the textarea field,
|
37
|
+
*
|
38
|
+
* **Note**: Consumers must set the help-text-type with 'error' and
|
39
|
+
* help-text attribute with the error message using limitexceeded event.
|
40
|
+
* The same help-text value will be used for the validation message to be displayed.
|
41
|
+
*
|
42
|
+
* @tagname mdc-textarea
|
43
|
+
*
|
44
|
+
* @event input - (React: onInput) This event is dispatched when the value of the textarea field changes (every press).
|
45
|
+
* @event change - (React: onChange) This event is dispatched when the value of the textarea field changes (on blur).
|
46
|
+
* @event focus - (React: onFocus) This event is dispatched when the textarea receives focus.
|
47
|
+
* @event blur - (React: onBlur) This event is dispatched when the textarea loses focus.
|
48
|
+
* @event limitexceeded - (React: onLimitExceeded) This event is dispatched once when the character limit
|
49
|
+
* exceeds or restored.
|
50
|
+
*
|
51
|
+
*
|
52
|
+
* @dependency mdc-icon
|
53
|
+
* @dependency mdc-text
|
54
|
+
* @dependency mdc-button
|
55
|
+
*
|
56
|
+
* @cssproperty --mdc-textarea-disabled-border-color - Border color for the textarea container when disabled
|
57
|
+
* @cssproperty --mdc-textarea-disabled-text-color - Text color for the textarea field when disabled
|
58
|
+
* @cssproperty --mdc-textarea-disabled-background-color - Background color for the textarea field when disabled
|
59
|
+
* @cssproperty --mdc-textarea-text-color - Text color for the textarea field
|
60
|
+
* @cssproperty --mdc-textarea-background-color - Background color for the textarea field
|
61
|
+
* @cssproperty --mdc-textarea-border-color - Border color for the textarea field
|
62
|
+
* @cssproperty --mdc-textarea-text-secondary-normal - Text color for the character counter
|
63
|
+
* @cssproperty --mdc-textarea-error-border-color - Border color for the error related help text
|
64
|
+
* @cssproperty --mdc-textarea-warning-border-color - Border color for the warning related help text
|
65
|
+
* @cssproperty --mdc-textarea-success-border-color - Border color for the success related help text
|
66
|
+
* @cssproperty --mdc-textarea-primary-border-color - Border color for the priority related help text
|
67
|
+
* @cssproperty --mdc-textarea-hover-background-color - Background color for the textarea container when hover
|
68
|
+
* @cssproperty --mdc-textarea-focused-background-color - Background color for the textarea container when focused
|
69
|
+
* @cssproperty --mdc-textarea-focused-border-color - Border color for the textarea container when focused
|
70
|
+
*/
|
71
|
+
class Textarea extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
|
72
|
+
get textarea() {
|
73
|
+
return this.inputElement;
|
74
|
+
}
|
75
|
+
constructor() {
|
76
|
+
var _a;
|
77
|
+
super();
|
78
|
+
/**
|
79
|
+
* readonly attribute of the textarea field. If true, the textarea field is read-only.
|
80
|
+
* @default false
|
81
|
+
*/
|
82
|
+
this.readonly = false;
|
83
|
+
/**
|
84
|
+
* The rows attribute specifies the visible number of lines in a text area.
|
85
|
+
* @default 5
|
86
|
+
*/
|
87
|
+
this.rows = DEFAULTS.ROWS;
|
88
|
+
/**
|
89
|
+
* The cols attribute specifies the visible number of lines in a text area.
|
90
|
+
* @default 40
|
91
|
+
*/
|
92
|
+
this.cols = DEFAULTS.COLS;
|
93
|
+
/**
|
94
|
+
* The wrap attribute specifies how the text in a text area is to be wrapped when submitted in a form.
|
95
|
+
* @default 'soft'
|
96
|
+
*/
|
97
|
+
this.wrap = WRAP.SOFT;
|
98
|
+
/**
|
99
|
+
* The autocapitalize attribute of the textarea field.
|
100
|
+
* @default 'off'
|
101
|
+
*/
|
102
|
+
this.autocapitalize = AUTO_CAPITALIZE.OFF;
|
103
|
+
/**
|
104
|
+
* The autocomplete attribute of the textarea field.
|
105
|
+
* @default 'off'
|
106
|
+
*/
|
107
|
+
this.autocomplete = AUTO_COMPLETE.OFF;
|
108
|
+
/**
|
109
|
+
* If true, the textarea field is focused when the component is rendered.
|
110
|
+
* @default false
|
111
|
+
*/
|
112
|
+
this.autofocus = false;
|
113
|
+
/**
|
114
|
+
* The clear button when set to true, shows a clear button that clears the textarea field.
|
115
|
+
* @default false
|
116
|
+
*/
|
117
|
+
this.clearButton = false;
|
118
|
+
/**
|
119
|
+
* Aria label for the clear button. If clear button is set to true, this label is used for the clear button.
|
120
|
+
* @default ''
|
121
|
+
*/
|
122
|
+
this.clearAriaLabel = '';
|
123
|
+
this.characterLimitExceedingFired = false;
|
124
|
+
// Set the default value to the textarea field if the value is set through the text content directly
|
125
|
+
this.value = ((_a = this.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || this.value;
|
126
|
+
}
|
127
|
+
connectedCallback() {
|
128
|
+
super.connectedCallback();
|
129
|
+
this.updateComplete.then(() => {
|
130
|
+
if (this.textarea) {
|
131
|
+
this.textarea.checkValidity();
|
132
|
+
this.setTextareaValidity();
|
133
|
+
this.internals.setFormValue(this.textarea.value);
|
134
|
+
}
|
135
|
+
}).catch((error) => {
|
136
|
+
if (this.onerror) {
|
137
|
+
this.onerror(error);
|
138
|
+
}
|
139
|
+
});
|
140
|
+
}
|
141
|
+
setTextareaValidity() {
|
142
|
+
if (this.requiredLabel && this.validationMessage && this.value === '') {
|
143
|
+
this.textarea.setCustomValidity(this.validationMessage);
|
144
|
+
}
|
145
|
+
else if (this.maxCharacterLimit
|
146
|
+
&& this.value.length > this.maxCharacterLimit
|
147
|
+
&& this.helpTextType === VALIDATION.ERROR
|
148
|
+
&& this.helpText) {
|
149
|
+
// Set custom validity if the character limit is exceeded to stop form submission
|
150
|
+
// helptext and helptexttype will be set by the consumers.
|
151
|
+
this.textarea.setCustomValidity(this.helpText);
|
152
|
+
}
|
153
|
+
else {
|
154
|
+
this.textarea.setCustomValidity('');
|
155
|
+
}
|
156
|
+
this.setValidity();
|
157
|
+
}
|
158
|
+
/** @internal */
|
159
|
+
formResetCallback() {
|
160
|
+
this.value = '';
|
161
|
+
this.requestUpdate();
|
162
|
+
}
|
163
|
+
/** @internal */
|
164
|
+
formStateRestoreCallback(state) {
|
165
|
+
this.value = state;
|
166
|
+
}
|
167
|
+
/**
|
168
|
+
* Handles the value change of the textarea field.
|
169
|
+
* Sets the form value and updates the validity of the textarea field.
|
170
|
+
* @returns void
|
171
|
+
*/
|
172
|
+
handleValueChange() {
|
173
|
+
this.updateComplete.then(() => {
|
174
|
+
this.setTextareaValidity();
|
175
|
+
}).catch((error) => {
|
176
|
+
if (this.onerror) {
|
177
|
+
this.onerror(error);
|
178
|
+
}
|
179
|
+
});
|
180
|
+
}
|
181
|
+
updated(changedProperties) {
|
182
|
+
super.updated(changedProperties);
|
183
|
+
if (changedProperties.has('value')) {
|
184
|
+
this.handleValueChange();
|
185
|
+
this.handleCharacterOverflowStateChange();
|
186
|
+
}
|
187
|
+
}
|
188
|
+
/**
|
189
|
+
* This function is called when the attribute changes.
|
190
|
+
* It updates the validity of the textarea field based on the textarea field's validity.
|
191
|
+
*
|
192
|
+
* @param name - attribute name
|
193
|
+
* @param old - old value
|
194
|
+
* @param value - new value
|
195
|
+
*/
|
196
|
+
attributeChangedCallback(name, old, value) {
|
197
|
+
super.attributeChangedCallback(name, old, value);
|
198
|
+
const validationRelatedAttributes = [
|
199
|
+
'maxlength',
|
200
|
+
'minlength',
|
201
|
+
'required',
|
202
|
+
];
|
203
|
+
if (validationRelatedAttributes.includes(name)) {
|
204
|
+
this.updateComplete.then(() => {
|
205
|
+
this.setTextareaValidity();
|
206
|
+
}).catch((error) => {
|
207
|
+
if (this.onerror) {
|
208
|
+
this.onerror(error);
|
209
|
+
}
|
210
|
+
});
|
211
|
+
}
|
212
|
+
}
|
213
|
+
/**
|
214
|
+
* Dispatches the character overflow state change event.
|
215
|
+
* @returns void
|
216
|
+
*/
|
217
|
+
dispatchCharacterOverflowStateChangeEvent() {
|
218
|
+
this.dispatchEvent(new CustomEvent('limitexceeded', {
|
219
|
+
detail: {
|
220
|
+
currentCharacterCount: this.value.length,
|
221
|
+
maxCharacterLimit: this.maxCharacterLimit,
|
222
|
+
value: this.value,
|
223
|
+
},
|
224
|
+
bubbles: true,
|
225
|
+
composed: true,
|
226
|
+
}));
|
227
|
+
}
|
228
|
+
/**
|
229
|
+
* Handles the character overflow state change.
|
230
|
+
* Dispatches the character overflow state change event if the character limit is exceeded or restored.
|
231
|
+
* @returns void
|
232
|
+
*/
|
233
|
+
handleCharacterOverflowStateChange() {
|
234
|
+
if (this.maxCharacterLimit) {
|
235
|
+
if (this.value.length > this.maxCharacterLimit && !this.characterLimitExceedingFired) {
|
236
|
+
this.dispatchCharacterOverflowStateChangeEvent();
|
237
|
+
this.characterLimitExceedingFired = true;
|
238
|
+
}
|
239
|
+
else if (this.value.length <= this.maxCharacterLimit && this.characterLimitExceedingFired) {
|
240
|
+
this.dispatchCharacterOverflowStateChangeEvent();
|
241
|
+
this.characterLimitExceedingFired = false;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
/**
|
246
|
+
* Updates the value of the textarea field.
|
247
|
+
* Sets the form value.
|
248
|
+
* @returns void
|
249
|
+
*/
|
250
|
+
updateValue() {
|
251
|
+
this.value = this.textarea.value;
|
252
|
+
this.internals.setFormValue(this.textarea.value);
|
253
|
+
}
|
254
|
+
/**
|
255
|
+
* Handles the change event of the textarea field.
|
256
|
+
* Updates the value and sets the validity of the textarea field.
|
257
|
+
*
|
258
|
+
* The 'change' event does not bubble up through the shadow DOM as it was not composed.
|
259
|
+
* Therefore, we need to re-dispatch the same event to ensure it is propagated correctly.
|
260
|
+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/Event/composed
|
261
|
+
*
|
262
|
+
* @param event - Event which contains information about the value change.
|
263
|
+
*/
|
264
|
+
onChange(event) {
|
265
|
+
this.updateValue();
|
266
|
+
const EventConstructor = event.constructor;
|
267
|
+
this.dispatchEvent(new EventConstructor(event.type, event));
|
268
|
+
}
|
269
|
+
/**
|
270
|
+
* Handles the keydown event of the textarea field.
|
271
|
+
* Clears the textarea field when the 'Enter' key is pressed.
|
272
|
+
* @param event - Keyboard event
|
273
|
+
* @returns void
|
274
|
+
*/
|
275
|
+
handleKeyDown(event) {
|
276
|
+
if (['Enter'].includes(event.key)) {
|
277
|
+
event.preventDefault();
|
278
|
+
this.clearInputText();
|
279
|
+
}
|
280
|
+
}
|
281
|
+
/**
|
282
|
+
* Clears the textarea field.
|
283
|
+
* @returns void
|
284
|
+
*/
|
285
|
+
clearInputText() {
|
286
|
+
this.value = '';
|
287
|
+
this.textarea.focus();
|
288
|
+
}
|
289
|
+
/**
|
290
|
+
* Renders the clear button to clear the textarea field if the clearButton is set to true.
|
291
|
+
* @returns void
|
292
|
+
*/
|
293
|
+
renderClearButton() {
|
294
|
+
if (!this.clearButton) {
|
295
|
+
return nothing;
|
296
|
+
}
|
297
|
+
return html `
|
298
|
+
<mdc-button
|
299
|
+
part='clear-button'
|
300
|
+
class='own-focus-ring ${!this.value ? 'hidden' : ''}'
|
301
|
+
prefix-icon='${DEFAULTS.CLEAR_BUTTON_ICON}'
|
302
|
+
variant='${DEFAULTS.CLEAR_BUTTON_VARIANT}'
|
303
|
+
size="${DEFAULTS.CLEAR_BUTTON_SIZE}"
|
304
|
+
aria-label="${this.clearAriaLabel}"
|
305
|
+
?disabled=${this.disabled || this.readonly || !this.value}
|
306
|
+
@click=${this.clearInputText}
|
307
|
+
@keydown=${this.handleKeyDown}
|
308
|
+
></mdc-button>
|
309
|
+
`;
|
310
|
+
}
|
311
|
+
renderCharacterCounter() {
|
312
|
+
if (!this.maxCharacterLimit) {
|
313
|
+
return nothing;
|
314
|
+
}
|
315
|
+
return html `
|
316
|
+
<mdc-text
|
317
|
+
part="character-counter"
|
318
|
+
tagname="span"
|
319
|
+
type=${DEFAULTS.CHARACTER_COUNTER_TYPE}
|
320
|
+
>
|
321
|
+
${this.value.length < 10 ? `0${this.value.length}` : this.value.length}/${this.maxCharacterLimit}
|
322
|
+
</mdc-text>
|
323
|
+
`;
|
324
|
+
}
|
325
|
+
renderTextareaFooter() {
|
326
|
+
if (!this.helpText && !this.maxCharacterLimit) {
|
327
|
+
return nothing;
|
328
|
+
}
|
329
|
+
return html `
|
330
|
+
<div part="textarea-footer">
|
331
|
+
${this.renderHelperText()}
|
332
|
+
${this.renderCharacterCounter()}
|
333
|
+
</div>
|
334
|
+
`;
|
335
|
+
}
|
336
|
+
render() {
|
337
|
+
var _a;
|
338
|
+
return html `
|
339
|
+
${this.renderLabel()}
|
340
|
+
<div class="textarea-container mdc-focus-ring" part="textarea-container">
|
341
|
+
<textarea
|
342
|
+
aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
|
343
|
+
part='textarea'
|
344
|
+
id="${this.id}"
|
345
|
+
name="${this.name}"
|
346
|
+
.value="${this.value}"
|
347
|
+
?disabled="${this.disabled}"
|
348
|
+
?readonly="${this.readonly}"
|
349
|
+
?required="${!!this.requiredLabel}"
|
350
|
+
placeholder=${ifDefined(this.placeholder)}
|
351
|
+
rows=${ifDefined(this.rows)}
|
352
|
+
cols=${ifDefined(this.cols)}
|
353
|
+
wrap=${ifDefined(this.wrap)}
|
354
|
+
?autofocus="${this.autofocus}"
|
355
|
+
autocapitalize=${this.autocapitalize}
|
356
|
+
autocomplete=${this.autocomplete}
|
357
|
+
minlength=${ifDefined(this.minlength)}
|
358
|
+
maxlength=${ifDefined(this.maxlength)}
|
359
|
+
dirname=${ifDefined(this.dirname)}
|
360
|
+
@input=${this.updateValue}
|
361
|
+
@change=${this.onChange}
|
362
|
+
aria-describedby="${ifDefined(this.helpText ? FORMFIELD_DEFAULTS.HELPER_TEXT_ID : '')}"
|
363
|
+
aria-invalid="${this.helpTextType === 'error' ? 'true' : 'false'}"
|
364
|
+
></textarea>
|
365
|
+
${this.renderClearButton()}
|
366
|
+
</div>
|
367
|
+
${this.renderTextareaFooter()}
|
368
|
+
`;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
Textarea.styles = [...FormfieldWrapper.styles, ...styles];
|
372
|
+
__decorate([
|
373
|
+
property({ type: String }),
|
374
|
+
__metadata("design:type", String)
|
375
|
+
], Textarea.prototype, "placeholder", void 0);
|
376
|
+
__decorate([
|
377
|
+
property({ type: Boolean }),
|
378
|
+
__metadata("design:type", Object)
|
379
|
+
], Textarea.prototype, "readonly", void 0);
|
380
|
+
__decorate([
|
381
|
+
property({ type: Number }),
|
382
|
+
__metadata("design:type", Object)
|
383
|
+
], Textarea.prototype, "rows", void 0);
|
384
|
+
__decorate([
|
385
|
+
property({ type: Number }),
|
386
|
+
__metadata("design:type", Object)
|
387
|
+
], Textarea.prototype, "cols", void 0);
|
388
|
+
__decorate([
|
389
|
+
property({ type: String }),
|
390
|
+
__metadata("design:type", String)
|
391
|
+
], Textarea.prototype, "wrap", void 0);
|
392
|
+
__decorate([
|
393
|
+
property({ type: String }),
|
394
|
+
__metadata("design:type", String)
|
395
|
+
], Textarea.prototype, "autocapitalize", void 0);
|
396
|
+
__decorate([
|
397
|
+
property({ type: String }),
|
398
|
+
__metadata("design:type", String)
|
399
|
+
], Textarea.prototype, "autocomplete", void 0);
|
400
|
+
__decorate([
|
401
|
+
property({ type: Boolean }),
|
402
|
+
__metadata("design:type", Boolean)
|
403
|
+
], Textarea.prototype, "autofocus", void 0);
|
404
|
+
__decorate([
|
405
|
+
property({ type: String }),
|
406
|
+
__metadata("design:type", String)
|
407
|
+
], Textarea.prototype, "dirname", void 0);
|
408
|
+
__decorate([
|
409
|
+
property({ type: Number }),
|
410
|
+
__metadata("design:type", Number)
|
411
|
+
], Textarea.prototype, "maxlength", void 0);
|
412
|
+
__decorate([
|
413
|
+
property({ type: Number }),
|
414
|
+
__metadata("design:type", Number)
|
415
|
+
], Textarea.prototype, "minlength", void 0);
|
416
|
+
__decorate([
|
417
|
+
property({ type: Boolean, attribute: 'clear-button' }),
|
418
|
+
__metadata("design:type", Object)
|
419
|
+
], Textarea.prototype, "clearButton", void 0);
|
420
|
+
__decorate([
|
421
|
+
property({ type: String, attribute: 'clear-aria-label' }),
|
422
|
+
__metadata("design:type", Object)
|
423
|
+
], Textarea.prototype, "clearAriaLabel", void 0);
|
424
|
+
__decorate([
|
425
|
+
property({ type: Number, attribute: 'max-character-limit' }),
|
426
|
+
__metadata("design:type", Number)
|
427
|
+
], Textarea.prototype, "maxCharacterLimit", void 0);
|
428
|
+
__decorate([
|
429
|
+
query('textarea'),
|
430
|
+
__metadata("design:type", HTMLTextAreaElement)
|
431
|
+
], Textarea.prototype, "inputElement", void 0);
|
432
|
+
export default Textarea;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
declare const TAG_NAME: "mdc-textarea";
|
2
|
+
declare const WRAP: {
|
3
|
+
readonly HARD: "hard";
|
4
|
+
readonly SOFT: "soft";
|
5
|
+
};
|
6
|
+
declare const AUTO_COMPLETE: {
|
7
|
+
readonly OFF: "off";
|
8
|
+
readonly ON: "on";
|
9
|
+
};
|
10
|
+
declare const DEFAULTS: {
|
11
|
+
ICON_SIZE_VALUE: number;
|
12
|
+
ICON_SIZE_UNIT: string;
|
13
|
+
CLEAR_BUTTON_ICON: "cancel-bold";
|
14
|
+
CLEAR_BUTTON_VARIANT: "tertiary";
|
15
|
+
CLEAR_BUTTON_SIZE: 20;
|
16
|
+
CHARACTER_COUNTER_TYPE: "body-midsize-regular";
|
17
|
+
ROWS: number;
|
18
|
+
COLS: number;
|
19
|
+
WRAP: "soft";
|
20
|
+
};
|
21
|
+
export { TAG_NAME, WRAP, AUTO_COMPLETE, DEFAULTS };
|