@justeattakeaway/pie-textarea 0.4.0 → 0.5.0
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/README.md +10 -4
- package/custom-elements.json +156 -1
- package/dist/index.d.ts +66 -3
- package/dist/index.js +171 -98
- package/dist/react.d.ts +72 -4
- package/dist/react.js +14 -7
- package/package.json +1 -1
- package/src/defs.ts +39 -1
- package/src/index.ts +111 -5
- package/src/react.ts +11 -3
package/README.md
CHANGED
|
@@ -73,10 +73,16 @@ import { PieTextarea } from '@justeattakeaway/pie-textarea/dist/react';
|
|
|
73
73
|
## Props
|
|
74
74
|
|
|
75
75
|
| Property | Type | Default | Description |
|
|
76
|
-
|
|
77
|
-
| `disabled` | `boolean` | `false
|
|
78
|
-
| `size` | `
|
|
79
|
-
| `resize` | `
|
|
76
|
+
|---|---|---|---|
|
|
77
|
+
| `disabled` | `boolean` | `false`| Indicates whether or not the textarea is disabled. |
|
|
78
|
+
| `size` | `'small'`, `'medium'`, `'large'` | `'medium'` | The size of the textarea field. |
|
|
79
|
+
| `resize` | `'auto'`, `'manual'` | `'auto'` | Controls the resizing behaviour of the textarea. |
|
|
80
|
+
| `value` | `string` | `''` | The value of the textarea (used as a key/value pair in HTML forms with `name`). |
|
|
81
|
+
| `name` | `string` | `''` | The name of the textarea (used as a key/value pair with `value`). This is required in order to work properly with forms. |
|
|
82
|
+
| `autocomplete` | `string` | `''` | Allows the user to enable or disable autocomplete functionality on the textarea field. |
|
|
83
|
+
| `autoFocus` | `boolean` | `false` | If true, the textarea will be focused on the first render. |
|
|
84
|
+
| `readonly` | `boolean` | `false` | When true, the user cannot edit the control. Not the same as disabled. |
|
|
85
|
+
| `required` | `boolean` | `false` | If true, the textarea is required to have a value before submitting the form. If there is no value, then the component validity state will be invalid. |
|
|
80
86
|
|
|
81
87
|
In your markup or JSX, you can then use these to set the properties for the `pie-textarea` component:
|
|
82
88
|
|
package/custom-elements.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"type": {
|
|
35
35
|
"text": "DefaultProps"
|
|
36
36
|
},
|
|
37
|
-
"default": "{\n disabled: false,\n size: 'medium',\n resize: 'auto',\n}",
|
|
37
|
+
"default": "{\n disabled: false,\n size: 'medium',\n resize: 'auto',\n value: '',\n autoFocus: false,\n readonly: false,\n required: false,\n}",
|
|
38
38
|
"description": "Default values for optional properties that have default fallback values in the component."
|
|
39
39
|
}
|
|
40
40
|
],
|
|
@@ -83,6 +83,12 @@
|
|
|
83
83
|
"static": true,
|
|
84
84
|
"default": "{ ...LitElement.shadowRootOptions, delegatesFocus: true }"
|
|
85
85
|
},
|
|
86
|
+
{
|
|
87
|
+
"kind": "field",
|
|
88
|
+
"name": "value",
|
|
89
|
+
"privacy": "public",
|
|
90
|
+
"attribute": "value"
|
|
91
|
+
},
|
|
86
92
|
{
|
|
87
93
|
"kind": "field",
|
|
88
94
|
"name": "disabled",
|
|
@@ -102,6 +108,42 @@
|
|
|
102
108
|
"privacy": "public",
|
|
103
109
|
"attribute": "resize"
|
|
104
110
|
},
|
|
111
|
+
{
|
|
112
|
+
"kind": "field",
|
|
113
|
+
"name": "readonly",
|
|
114
|
+
"privacy": "public",
|
|
115
|
+
"attribute": "readonly"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"kind": "field",
|
|
119
|
+
"name": "autoFocus",
|
|
120
|
+
"privacy": "public",
|
|
121
|
+
"attribute": "autoFocus"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"kind": "field",
|
|
125
|
+
"name": "required",
|
|
126
|
+
"privacy": "public",
|
|
127
|
+
"attribute": "required"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"kind": "field",
|
|
131
|
+
"name": "name",
|
|
132
|
+
"type": {
|
|
133
|
+
"text": "TextareaProps['name'] | undefined"
|
|
134
|
+
},
|
|
135
|
+
"privacy": "public",
|
|
136
|
+
"attribute": "name"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"kind": "field",
|
|
140
|
+
"name": "autocomplete",
|
|
141
|
+
"type": {
|
|
142
|
+
"text": "TextareaProps['autocomplete'] | undefined"
|
|
143
|
+
},
|
|
144
|
+
"privacy": "public",
|
|
145
|
+
"attribute": "autocomplete"
|
|
146
|
+
},
|
|
105
147
|
{
|
|
106
148
|
"kind": "field",
|
|
107
149
|
"name": "_textarea",
|
|
@@ -115,13 +157,96 @@
|
|
|
115
157
|
"name": "_throttledResize",
|
|
116
158
|
"privacy": "private"
|
|
117
159
|
},
|
|
160
|
+
{
|
|
161
|
+
"kind": "field",
|
|
162
|
+
"name": "validity",
|
|
163
|
+
"type": {
|
|
164
|
+
"text": "ValidityState"
|
|
165
|
+
},
|
|
166
|
+
"privacy": "public",
|
|
167
|
+
"description": "(Read-only) returns a ValidityState with the validity states that this element is in.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity",
|
|
168
|
+
"readonly": true
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"kind": "method",
|
|
172
|
+
"name": "formDisabledCallback",
|
|
173
|
+
"privacy": "public",
|
|
174
|
+
"return": {
|
|
175
|
+
"type": {
|
|
176
|
+
"text": "void"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"parameters": [
|
|
180
|
+
{
|
|
181
|
+
"name": "disabled",
|
|
182
|
+
"type": {
|
|
183
|
+
"text": "boolean"
|
|
184
|
+
},
|
|
185
|
+
"description": "The latest disabled state of the input."
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"description": "Called after the disabled state of the element changes,\neither because the disabled attribute of this element was added or removed;\nor because the disabled state changed on a <fieldset> that's an ancestor of this element."
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"kind": "method",
|
|
192
|
+
"name": "formResetCallback",
|
|
193
|
+
"privacy": "public",
|
|
194
|
+
"return": {
|
|
195
|
+
"type": {
|
|
196
|
+
"text": "void"
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"description": "Called when the form that owns this component is reset.\nResets the value to the default value."
|
|
200
|
+
},
|
|
118
201
|
{
|
|
119
202
|
"kind": "method",
|
|
120
203
|
"name": "handleResize",
|
|
121
204
|
"privacy": "private"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"kind": "field",
|
|
208
|
+
"name": "handleInput",
|
|
209
|
+
"privacy": "private",
|
|
210
|
+
"description": "Handles data processing in response to the input event. The native input event is left to bubble up.",
|
|
211
|
+
"parameters": [
|
|
212
|
+
{
|
|
213
|
+
"description": "The input event.",
|
|
214
|
+
"name": "event"
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"kind": "field",
|
|
220
|
+
"name": "handleChange",
|
|
221
|
+
"privacy": "private"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"kind": "field",
|
|
225
|
+
"name": "handleKeyDown",
|
|
226
|
+
"privacy": "private"
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
"events": [
|
|
230
|
+
{
|
|
231
|
+
"type": {
|
|
232
|
+
"text": "InputEvent"
|
|
233
|
+
},
|
|
234
|
+
"description": "when the textarea value is changed.",
|
|
235
|
+
"name": "input"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"type": {
|
|
239
|
+
"text": "CustomEvent"
|
|
240
|
+
},
|
|
241
|
+
"description": "when the textarea value is changed.",
|
|
242
|
+
"name": "change"
|
|
122
243
|
}
|
|
123
244
|
],
|
|
124
245
|
"attributes": [
|
|
246
|
+
{
|
|
247
|
+
"name": "value",
|
|
248
|
+
"fieldName": "value"
|
|
249
|
+
},
|
|
125
250
|
{
|
|
126
251
|
"name": "disabled",
|
|
127
252
|
"fieldName": "disabled"
|
|
@@ -133,9 +258,39 @@
|
|
|
133
258
|
{
|
|
134
259
|
"name": "resize",
|
|
135
260
|
"fieldName": "resize"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "readonly",
|
|
264
|
+
"fieldName": "readonly"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"name": "autoFocus",
|
|
268
|
+
"fieldName": "autoFocus"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "required",
|
|
272
|
+
"fieldName": "required"
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
"name": "name",
|
|
276
|
+
"type": {
|
|
277
|
+
"text": "TextareaProps['name'] | undefined"
|
|
278
|
+
},
|
|
279
|
+
"fieldName": "name"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"name": "autocomplete",
|
|
283
|
+
"type": {
|
|
284
|
+
"text": "TextareaProps['autocomplete'] | undefined"
|
|
285
|
+
},
|
|
286
|
+
"fieldName": "autocomplete"
|
|
136
287
|
}
|
|
137
288
|
],
|
|
138
289
|
"mixins": [
|
|
290
|
+
{
|
|
291
|
+
"name": "FormControlMixin",
|
|
292
|
+
"package": "@justeattakeaway/pie-webc-core"
|
|
293
|
+
},
|
|
139
294
|
{
|
|
140
295
|
"name": "RtlMixin",
|
|
141
296
|
"package": "@justeattakeaway/pie-webc-core"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
|
+
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
3
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
4
5
|
import type { LitElement } from 'lit';
|
|
5
6
|
import type { PropertyValues } from 'lit';
|
|
@@ -9,7 +10,7 @@ import type { TemplateResult } from 'lit-html';
|
|
|
9
10
|
/**
|
|
10
11
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
11
12
|
*/
|
|
12
|
-
declare type DefaultProps = ComponentDefaultProps<TextareaProps
|
|
13
|
+
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete'>>;
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -18,6 +19,8 @@ export declare const defaultProps: DefaultProps;
|
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @tagname pie-textarea
|
|
22
|
+
* @event {InputEvent} input - when the textarea value is changed.
|
|
23
|
+
* @event {CustomEvent} change - when the textarea value is changed.
|
|
21
24
|
*/
|
|
22
25
|
export declare class PieTextarea extends PieTextarea_base implements TextareaProps {
|
|
23
26
|
static shadowRootOptions: {
|
|
@@ -25,18 +28,50 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
|
|
|
25
28
|
mode: ShadowRootMode;
|
|
26
29
|
slotAssignment?: SlotAssignmentMode | undefined;
|
|
27
30
|
};
|
|
31
|
+
value: string;
|
|
28
32
|
disabled: boolean;
|
|
29
33
|
size: "small" | "medium" | "large";
|
|
30
34
|
resize: "auto" | "manual";
|
|
35
|
+
readonly: boolean;
|
|
36
|
+
autoFocus: boolean;
|
|
37
|
+
required: boolean;
|
|
38
|
+
name?: TextareaProps['name'];
|
|
39
|
+
autocomplete?: TextareaProps['autocomplete'];
|
|
31
40
|
private _textarea;
|
|
32
41
|
private _throttledResize;
|
|
42
|
+
/**
|
|
43
|
+
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
44
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
45
|
+
*/
|
|
46
|
+
get validity(): ValidityState;
|
|
47
|
+
/**
|
|
48
|
+
* Called after the disabled state of the element changes,
|
|
49
|
+
* either because the disabled attribute of this element was added or removed;
|
|
50
|
+
* or because the disabled state changed on a <fieldset> that's an ancestor of this element.
|
|
51
|
+
* @param disabled - The latest disabled state of the input.
|
|
52
|
+
*/
|
|
53
|
+
formDisabledCallback(disabled: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Called when the form that owns this component is reset.
|
|
56
|
+
* Resets the value to the default value.
|
|
57
|
+
*/
|
|
58
|
+
formResetCallback(): void;
|
|
59
|
+
protected firstUpdated(): void;
|
|
33
60
|
private handleResize;
|
|
34
|
-
updated(changedProperties: PropertyValues<this>): void;
|
|
61
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
62
|
+
/**
|
|
63
|
+
* Handles data processing in response to the input event. The native input event is left to bubble up.
|
|
64
|
+
* @param event - The input event.
|
|
65
|
+
*/
|
|
66
|
+
private handleInput;
|
|
67
|
+
private handleChange;
|
|
68
|
+
private handleKeyDown;
|
|
69
|
+
disconnectedCallback(): void;
|
|
35
70
|
render(): TemplateResult<1>;
|
|
36
71
|
static styles: CSSResult;
|
|
37
72
|
}
|
|
38
73
|
|
|
39
|
-
declare const PieTextarea_base: GenericConstructor<RTLInterface> & typeof LitElement;
|
|
74
|
+
declare const PieTextarea_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
40
75
|
|
|
41
76
|
export declare const resizeModes: readonly ["auto", "manual"];
|
|
42
77
|
|
|
@@ -57,6 +92,34 @@ export declare interface TextareaProps {
|
|
|
57
92
|
* When set to `manual`, the textarea will not resize automatically but can be resized by the user.
|
|
58
93
|
*/
|
|
59
94
|
resize?: typeof resizeModes[number];
|
|
95
|
+
/**
|
|
96
|
+
* The value of the textarea (used as a key/value pair in HTML forms with `name`).
|
|
97
|
+
*/
|
|
98
|
+
value: string;
|
|
99
|
+
/**
|
|
100
|
+
* The name of the textarea (used as a key/value pair with `value`). This is required in order to work properly with forms.
|
|
101
|
+
*/
|
|
102
|
+
name?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Allows the user to enable or disable autocomplete functionality on the textarea field.
|
|
105
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for more information and values.
|
|
106
|
+
*/
|
|
107
|
+
autocomplete?: string;
|
|
108
|
+
/**
|
|
109
|
+
* If true, the textarea will be focused on the first render.
|
|
110
|
+
* No more than one element in the document or dialog may have the autofocus attribute. If applied to multiple elements the first one will receive focus.
|
|
111
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) for more information.
|
|
112
|
+
*/
|
|
113
|
+
autoFocus?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* When true, the user cannot edit the control. Not the same as disabled.
|
|
116
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) for more information.
|
|
117
|
+
*/
|
|
118
|
+
readonly?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* If true, the textarea is required to have a value before submitting the form. If there is no value, then the component validity state will be invalid.
|
|
121
|
+
*/
|
|
122
|
+
required?: boolean;
|
|
60
123
|
}
|
|
61
124
|
|
|
62
125
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,160 +1,233 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { LitElement as F, html as q, unsafeCSS as B } from "lit";
|
|
2
|
+
import { property as p, query as N } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as W } from "lit/directives/if-defined.js";
|
|
4
|
+
import { live as V } from "lit/directives/live.js";
|
|
5
|
+
import { FormControlMixin as A, RtlMixin as K, wrapNativeEvent as G, validPropertyValues as I, defineCustomElement as H } from "@justeattakeaway/pie-webc-core";
|
|
6
|
+
var m = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
7
|
+
function U(e) {
|
|
6
8
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
7
9
|
}
|
|
8
|
-
var
|
|
9
|
-
return
|
|
10
|
+
var R = "Expected a function", w = 0 / 0, X = "[object Symbol]", J = /^\s+|\s+$/g, Q = /^[-+]0x[0-9a-f]+$/i, Y = /^0b[01]+$/i, Z = /^0o[0-7]+$/i, ee = parseInt, te = typeof m == "object" && m && m.Object === Object && m, ae = typeof self == "object" && self && self.Object === Object && self, re = te || ae || Function("return this")(), ie = Object.prototype, ne = ie.toString, oe = Math.max, se = Math.min, j = function() {
|
|
11
|
+
return re.Date.now();
|
|
10
12
|
};
|
|
11
|
-
function
|
|
12
|
-
var
|
|
13
|
+
function le(e, t, a) {
|
|
14
|
+
var n, r, d, l, o, h, x = 0, T = !1, v = !1, z = !0;
|
|
13
15
|
if (typeof e != "function")
|
|
14
|
-
throw new TypeError(
|
|
15
|
-
t =
|
|
16
|
-
function
|
|
17
|
-
var
|
|
18
|
-
return
|
|
16
|
+
throw new TypeError(R);
|
|
17
|
+
t = C(t) || 0, y(a) && (T = !!a.leading, v = "maxWait" in a, d = v ? oe(C(a.maxWait) || 0, t) : d, z = "trailing" in a ? !!a.trailing : z);
|
|
18
|
+
function k(i) {
|
|
19
|
+
var f = n, g = r;
|
|
20
|
+
return n = r = void 0, x = i, l = e.apply(g, f), l;
|
|
19
21
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
22
|
+
function D(i) {
|
|
23
|
+
return x = i, o = setTimeout(b, t), T ? k(i) : l;
|
|
22
24
|
}
|
|
23
|
-
function
|
|
24
|
-
var
|
|
25
|
-
return
|
|
25
|
+
function P(i) {
|
|
26
|
+
var f = i - h, g = i - x, $ = t - f;
|
|
27
|
+
return v ? se($, d - g) : $;
|
|
26
28
|
}
|
|
27
|
-
function
|
|
28
|
-
var
|
|
29
|
-
return
|
|
29
|
+
function E(i) {
|
|
30
|
+
var f = i - h, g = i - x;
|
|
31
|
+
return h === void 0 || f >= t || f < 0 || v && g >= d;
|
|
30
32
|
}
|
|
31
|
-
function
|
|
32
|
-
var
|
|
33
|
-
if (
|
|
34
|
-
return S(
|
|
35
|
-
o = setTimeout(
|
|
33
|
+
function b() {
|
|
34
|
+
var i = j();
|
|
35
|
+
if (E(i))
|
|
36
|
+
return S(i);
|
|
37
|
+
o = setTimeout(b, P(i));
|
|
36
38
|
}
|
|
37
|
-
function S(
|
|
38
|
-
return o = void 0,
|
|
39
|
+
function S(i) {
|
|
40
|
+
return o = void 0, z && n ? k(i) : (n = r = void 0, l);
|
|
39
41
|
}
|
|
40
42
|
function L() {
|
|
41
|
-
o !== void 0 && clearTimeout(o),
|
|
43
|
+
o !== void 0 && clearTimeout(o), x = 0, n = h = r = o = void 0;
|
|
42
44
|
}
|
|
43
|
-
function
|
|
44
|
-
return o === void 0 ?
|
|
45
|
+
function M() {
|
|
46
|
+
return o === void 0 ? l : S(j());
|
|
45
47
|
}
|
|
46
|
-
function
|
|
47
|
-
var
|
|
48
|
-
if (
|
|
48
|
+
function _() {
|
|
49
|
+
var i = j(), f = E(i);
|
|
50
|
+
if (n = arguments, r = this, h = i, f) {
|
|
49
51
|
if (o === void 0)
|
|
50
|
-
return
|
|
51
|
-
if (
|
|
52
|
-
return o = setTimeout(
|
|
52
|
+
return D(h);
|
|
53
|
+
if (v)
|
|
54
|
+
return o = setTimeout(b, t), k(h);
|
|
53
55
|
}
|
|
54
|
-
return o === void 0 && (o = setTimeout(
|
|
56
|
+
return o === void 0 && (o = setTimeout(b, t)), l;
|
|
55
57
|
}
|
|
56
|
-
return
|
|
58
|
+
return _.cancel = L, _.flush = M, _;
|
|
57
59
|
}
|
|
58
|
-
function
|
|
59
|
-
var
|
|
60
|
+
function de(e, t, a) {
|
|
61
|
+
var n = !0, r = !0;
|
|
60
62
|
if (typeof e != "function")
|
|
61
|
-
throw new TypeError(
|
|
62
|
-
return
|
|
63
|
-
leading:
|
|
63
|
+
throw new TypeError(R);
|
|
64
|
+
return y(a) && (n = "leading" in a ? !!a.leading : n, r = "trailing" in a ? !!a.trailing : r), le(e, t, {
|
|
65
|
+
leading: n,
|
|
64
66
|
maxWait: t,
|
|
65
|
-
trailing:
|
|
67
|
+
trailing: r
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
|
-
function
|
|
70
|
+
function y(e) {
|
|
69
71
|
var t = typeof e;
|
|
70
72
|
return !!e && (t == "object" || t == "function");
|
|
71
73
|
}
|
|
72
|
-
function
|
|
74
|
+
function ce(e) {
|
|
73
75
|
return !!e && typeof e == "object";
|
|
74
76
|
}
|
|
75
|
-
function
|
|
76
|
-
return typeof e == "symbol" ||
|
|
77
|
+
function ue(e) {
|
|
78
|
+
return typeof e == "symbol" || ce(e) && ne.call(e) == X;
|
|
77
79
|
}
|
|
78
|
-
function
|
|
80
|
+
function C(e) {
|
|
79
81
|
if (typeof e == "number")
|
|
80
82
|
return e;
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
83
|
-
if (
|
|
83
|
+
if (ue(e))
|
|
84
|
+
return w;
|
|
85
|
+
if (y(e)) {
|
|
84
86
|
var t = typeof e.valueOf == "function" ? e.valueOf() : e;
|
|
85
|
-
e =
|
|
87
|
+
e = y(t) ? t + "" : t;
|
|
86
88
|
}
|
|
87
89
|
if (typeof e != "string")
|
|
88
90
|
return e === 0 ? e : +e;
|
|
89
|
-
e = e.replace(
|
|
90
|
-
var
|
|
91
|
-
return
|
|
91
|
+
e = e.replace(J, "");
|
|
92
|
+
var a = Y.test(e);
|
|
93
|
+
return a || Z.test(e) ? ee(e.slice(2), a ? 2 : 8) : Q.test(e) ? w : +e;
|
|
92
94
|
}
|
|
93
|
-
var
|
|
94
|
-
const
|
|
95
|
-
`,
|
|
95
|
+
var he = de;
|
|
96
|
+
const pe = /* @__PURE__ */ U(he), fe = `*,*:after,*:before{box-sizing:inherit}.c-textareaWrapper{--textarea-line-height: calc(var(--dt-font-body-l-line-height) * 1px);--textarea-border-thickness: 1px;--textarea-resize: none;--textarea-padding-inline: var(--dt-spacing-d);--textarea-padding-block: var(--dt-spacing-c);--textarea-background-color: var(--dt-color-container-default);--textarea-border-color: var(--dt-color-interactive-form);--textarea-content-color: var(--dt-color-content-default);--textarea-height: calc((var(--textarea-line-height) * 2) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2));line-height:0}.c-textareaWrapper textarea{font-size:calc(var(--dt-font-body-l-size) * 1px);line-height:var(--textarea-line-height);font-family:var(--dt-font-body-l-family);resize:var(--textarea-resize);border:var(--textarea-border-thickness) solid var(--textarea-border-color);background-color:var(--textarea-background-color);color:var(--textarea-content-color);border-radius:var(--dt-radius-rounded-c);block-size:var(--textarea-height);max-block-size:var(--textarea-max-height);min-block-size:var(--textarea-min-height);padding-block-start:var(--textarea-padding-block);padding-block-end:var(--textarea-padding-block);padding-inline-start:var(--textarea-padding-inline);padding-inline-end:var(--textarea-padding-inline)}.c-textareaWrapper textarea[disabled]{--textarea-background-color: var(--dt-color-disabled-01);--textarea-border-color: var(--dt-color-disabled-01);--textarea-content-color: var(--dt-color-content-disabled)}@media (hover: hover){.c-textareaWrapper textarea:hover:not([disabled]){--textarea-background-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))))}}.c-textareaWrapper textarea:focus-visible{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-textareaWrapper[data-pie-size=large]{--textarea-padding-block: var(--dt-spacing-d)}.c-textareaWrapper[data-pie-size=small]{--textarea-padding-block: var(--dt-spacing-b)}.c-textareaWrapper[data-pie-resize=manual]{--textarea-resize: vertical;--textarea-min-height: calc((var(--textarea-line-height) * 1) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2))}@media (pointer: coarse){.c-textareaWrapper[data-pie-resize=manual]{--textarea-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2));--textarea-min-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2));--textarea-max-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2));--textarea-resize: none}}.c-textareaWrapper[data-pie-resize=auto]{--textarea-max-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2) + (var(--textarea-border-thickness) * 2));--textarea-min-height: var(--textarea-height)}
|
|
97
|
+
`, xe = ["small", "medium", "large"], ve = ["auto", "manual"], c = {
|
|
96
98
|
disabled: !1,
|
|
97
99
|
size: "medium",
|
|
98
|
-
resize: "auto"
|
|
100
|
+
resize: "auto",
|
|
101
|
+
value: "",
|
|
102
|
+
autoFocus: !1,
|
|
103
|
+
readonly: !1,
|
|
104
|
+
required: !1
|
|
99
105
|
};
|
|
100
|
-
var
|
|
101
|
-
for (var
|
|
102
|
-
(
|
|
103
|
-
return
|
|
106
|
+
var ge = Object.defineProperty, be = Object.getOwnPropertyDescriptor, u = (e, t, a, n) => {
|
|
107
|
+
for (var r = n > 1 ? void 0 : n ? be(t, a) : t, d = e.length - 1, l; d >= 0; d--)
|
|
108
|
+
(l = e[d]) && (r = (n ? l(t, a, r) : l(r)) || r);
|
|
109
|
+
return n && r && ge(t, a, r), r;
|
|
104
110
|
};
|
|
105
|
-
const
|
|
106
|
-
class
|
|
111
|
+
const O = "pie-textarea";
|
|
112
|
+
class s extends A(K(F)) {
|
|
107
113
|
constructor() {
|
|
108
|
-
super(...arguments), this.disabled =
|
|
114
|
+
super(...arguments), this.value = c.value, this.disabled = c.disabled, this.size = c.size, this.resize = c.resize, this.readonly = c.readonly, this.autoFocus = c.autoFocus, this.required = c.required, this._throttledResize = pe(() => {
|
|
109
115
|
this.resize === "auto" && (this._textarea.style.height = "auto", this._textarea.style.height = `${this._textarea.scrollHeight + 2}px`);
|
|
110
|
-
}, 100)
|
|
116
|
+
}, 100), this.handleInput = (t) => {
|
|
117
|
+
this.value = t.target.value, this._internals.setFormValue(this.value), this.handleResize();
|
|
118
|
+
}, this.handleChange = (t) => {
|
|
119
|
+
const a = G(t);
|
|
120
|
+
this.dispatchEvent(a);
|
|
121
|
+
}, this.handleKeyDown = (t) => {
|
|
122
|
+
t.key === "Enter" && t.stopPropagation();
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
127
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
128
|
+
*/
|
|
129
|
+
get validity() {
|
|
130
|
+
return this._textarea.validity;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Called after the disabled state of the element changes,
|
|
134
|
+
* either because the disabled attribute of this element was added or removed;
|
|
135
|
+
* or because the disabled state changed on a <fieldset> that's an ancestor of this element.
|
|
136
|
+
* @param disabled - The latest disabled state of the input.
|
|
137
|
+
*/
|
|
138
|
+
formDisabledCallback(t) {
|
|
139
|
+
this.disabled = t;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Called when the form that owns this component is reset.
|
|
143
|
+
* Resets the value to the default value.
|
|
144
|
+
*/
|
|
145
|
+
formResetCallback() {
|
|
146
|
+
this.value = c.value, this._internals.setFormValue(this.value);
|
|
147
|
+
}
|
|
148
|
+
firstUpdated() {
|
|
149
|
+
this._internals.setFormValue(this.value), this._textarea.addEventListener("keydown", this.handleKeyDown);
|
|
111
150
|
}
|
|
112
151
|
handleResize() {
|
|
113
152
|
this._throttledResize();
|
|
114
153
|
}
|
|
115
154
|
updated(t) {
|
|
116
|
-
this.resize === "auto" && (t.has("resize") || t.has("size")) && this.handleResize();
|
|
155
|
+
this.resize === "auto" && (t.has("resize") || t.has("size")) && this.handleResize(), t.has("value") && this._internals.setFormValue(this.value);
|
|
156
|
+
}
|
|
157
|
+
disconnectedCallback() {
|
|
158
|
+
this._textarea.removeEventListener("keydown", this.handleKeyDown);
|
|
117
159
|
}
|
|
118
160
|
render() {
|
|
119
161
|
const {
|
|
120
162
|
disabled: t,
|
|
121
|
-
resize:
|
|
122
|
-
size:
|
|
163
|
+
resize: a,
|
|
164
|
+
size: n,
|
|
165
|
+
autocomplete: r,
|
|
166
|
+
autoFocus: d,
|
|
167
|
+
name: l,
|
|
168
|
+
readonly: o,
|
|
169
|
+
value: h,
|
|
170
|
+
required: x
|
|
123
171
|
} = this;
|
|
124
|
-
return
|
|
172
|
+
return q`
|
|
125
173
|
<div
|
|
126
174
|
class="c-textareaWrapper"
|
|
127
175
|
data-test-id="pie-textarea-wrapper"
|
|
128
|
-
data-pie-size="${
|
|
129
|
-
data-pie-resize="${
|
|
176
|
+
data-pie-size="${n}"
|
|
177
|
+
data-pie-resize="${a}">
|
|
130
178
|
<textarea
|
|
131
|
-
|
|
132
|
-
|
|
179
|
+
name=${W(l)}
|
|
180
|
+
autocomplete=${W(r)}
|
|
181
|
+
.value=${V(h)}
|
|
182
|
+
?autofocus=${d}
|
|
183
|
+
?readonly=${o}
|
|
184
|
+
?required=${x}
|
|
133
185
|
?disabled=${t}
|
|
186
|
+
@input=${this.handleInput}
|
|
187
|
+
@change=${this.handleChange}
|
|
188
|
+
data-test-id="pie-textarea"
|
|
134
189
|
></textarea>
|
|
135
190
|
</div>`;
|
|
136
191
|
}
|
|
137
192
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
],
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
O
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
193
|
+
s.shadowRootOptions = { ...F.shadowRootOptions, delegatesFocus: !0 };
|
|
194
|
+
s.styles = B(fe);
|
|
195
|
+
u([
|
|
196
|
+
p({ type: String })
|
|
197
|
+
], s.prototype, "value", 2);
|
|
198
|
+
u([
|
|
199
|
+
p({ type: Boolean, reflect: !0 })
|
|
200
|
+
], s.prototype, "disabled", 2);
|
|
201
|
+
u([
|
|
202
|
+
p({ type: String }),
|
|
203
|
+
I(O, xe, c.size)
|
|
204
|
+
], s.prototype, "size", 2);
|
|
205
|
+
u([
|
|
206
|
+
p({ type: String }),
|
|
207
|
+
I(O, ve, c.resize)
|
|
208
|
+
], s.prototype, "resize", 2);
|
|
209
|
+
u([
|
|
210
|
+
p({ type: Boolean })
|
|
211
|
+
], s.prototype, "readonly", 2);
|
|
212
|
+
u([
|
|
213
|
+
p({ type: Boolean })
|
|
214
|
+
], s.prototype, "autoFocus", 2);
|
|
215
|
+
u([
|
|
216
|
+
p({ type: Boolean })
|
|
217
|
+
], s.prototype, "required", 2);
|
|
218
|
+
u([
|
|
219
|
+
p({ type: String })
|
|
220
|
+
], s.prototype, "name", 2);
|
|
221
|
+
u([
|
|
222
|
+
p({ type: String })
|
|
223
|
+
], s.prototype, "autocomplete", 2);
|
|
224
|
+
u([
|
|
152
225
|
N("textarea")
|
|
153
|
-
],
|
|
154
|
-
|
|
226
|
+
], s.prototype, "_textarea", 2);
|
|
227
|
+
H(O, s);
|
|
155
228
|
export {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
229
|
+
s as PieTextarea,
|
|
230
|
+
c as defaultProps,
|
|
231
|
+
ve as resizeModes,
|
|
232
|
+
xe as sizes
|
|
160
233
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
|
+
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
3
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
4
5
|
import type { LitElement } from 'lit';
|
|
5
6
|
import type { PropertyValues } from 'lit';
|
|
@@ -10,17 +11,19 @@ import type { TemplateResult } from 'lit-html';
|
|
|
10
11
|
/**
|
|
11
12
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
12
13
|
*/
|
|
13
|
-
declare type DefaultProps = ComponentDefaultProps<TextareaProps
|
|
14
|
+
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete'>>;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Default values for optional properties that have default fallback values in the component.
|
|
17
18
|
*/
|
|
18
19
|
export declare const defaultProps: DefaultProps;
|
|
19
20
|
|
|
20
|
-
export declare const PieTextarea: React_2.ForwardRefExoticComponent<TextareaProps & React_2.RefAttributes<PieTextarea_2> & ReactBaseType>;
|
|
21
|
+
export declare const PieTextarea: React_2.ForwardRefExoticComponent<TextareaProps & React_2.RefAttributes<PieTextarea_2> & PieTextareaEvents & ReactBaseType>;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @tagname pie-textarea
|
|
25
|
+
* @event {InputEvent} input - when the textarea value is changed.
|
|
26
|
+
* @event {CustomEvent} change - when the textarea value is changed.
|
|
24
27
|
*/
|
|
25
28
|
declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps {
|
|
26
29
|
static shadowRootOptions: {
|
|
@@ -28,18 +31,55 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps {
|
|
|
28
31
|
mode: ShadowRootMode;
|
|
29
32
|
slotAssignment?: SlotAssignmentMode | undefined;
|
|
30
33
|
};
|
|
34
|
+
value: string;
|
|
31
35
|
disabled: boolean;
|
|
32
36
|
size: "small" | "medium" | "large";
|
|
33
37
|
resize: "auto" | "manual";
|
|
38
|
+
readonly: boolean;
|
|
39
|
+
autoFocus: boolean;
|
|
40
|
+
required: boolean;
|
|
41
|
+
name?: TextareaProps['name'];
|
|
42
|
+
autocomplete?: TextareaProps['autocomplete'];
|
|
34
43
|
private _textarea;
|
|
35
44
|
private _throttledResize;
|
|
45
|
+
/**
|
|
46
|
+
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
47
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
48
|
+
*/
|
|
49
|
+
get validity(): ValidityState;
|
|
50
|
+
/**
|
|
51
|
+
* Called after the disabled state of the element changes,
|
|
52
|
+
* either because the disabled attribute of this element was added or removed;
|
|
53
|
+
* or because the disabled state changed on a <fieldset> that's an ancestor of this element.
|
|
54
|
+
* @param disabled - The latest disabled state of the input.
|
|
55
|
+
*/
|
|
56
|
+
formDisabledCallback(disabled: boolean): void;
|
|
57
|
+
/**
|
|
58
|
+
* Called when the form that owns this component is reset.
|
|
59
|
+
* Resets the value to the default value.
|
|
60
|
+
*/
|
|
61
|
+
formResetCallback(): void;
|
|
62
|
+
protected firstUpdated(): void;
|
|
36
63
|
private handleResize;
|
|
37
|
-
updated(changedProperties: PropertyValues<this>): void;
|
|
64
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Handles data processing in response to the input event. The native input event is left to bubble up.
|
|
67
|
+
* @param event - The input event.
|
|
68
|
+
*/
|
|
69
|
+
private handleInput;
|
|
70
|
+
private handleChange;
|
|
71
|
+
private handleKeyDown;
|
|
72
|
+
disconnectedCallback(): void;
|
|
38
73
|
render(): TemplateResult<1>;
|
|
39
74
|
static styles: CSSResult;
|
|
40
75
|
}
|
|
41
76
|
|
|
42
|
-
declare const PieTextarea_base: GenericConstructor<RTLInterface> & typeof LitElement;
|
|
77
|
+
declare const PieTextarea_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
|
|
78
|
+
|
|
79
|
+
declare type PieTextareaEvents = {
|
|
80
|
+
onInput?: (event: InputEvent) => void;
|
|
81
|
+
onChange?: (event: CustomEvent) => void;
|
|
82
|
+
};
|
|
43
83
|
|
|
44
84
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLTextAreaElement>;
|
|
45
85
|
|
|
@@ -62,6 +102,34 @@ export declare interface TextareaProps {
|
|
|
62
102
|
* When set to `manual`, the textarea will not resize automatically but can be resized by the user.
|
|
63
103
|
*/
|
|
64
104
|
resize?: typeof resizeModes[number];
|
|
105
|
+
/**
|
|
106
|
+
* The value of the textarea (used as a key/value pair in HTML forms with `name`).
|
|
107
|
+
*/
|
|
108
|
+
value: string;
|
|
109
|
+
/**
|
|
110
|
+
* The name of the textarea (used as a key/value pair with `value`). This is required in order to work properly with forms.
|
|
111
|
+
*/
|
|
112
|
+
name?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Allows the user to enable or disable autocomplete functionality on the textarea field.
|
|
115
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for more information and values.
|
|
116
|
+
*/
|
|
117
|
+
autocomplete?: string;
|
|
118
|
+
/**
|
|
119
|
+
* If true, the textarea will be focused on the first render.
|
|
120
|
+
* No more than one element in the document or dialog may have the autofocus attribute. If applied to multiple elements the first one will receive focus.
|
|
121
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) for more information.
|
|
122
|
+
*/
|
|
123
|
+
autoFocus?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* When true, the user cannot edit the control. Not the same as disabled.
|
|
126
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) for more information.
|
|
127
|
+
*/
|
|
128
|
+
readonly?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* If true, the textarea is required to have a value before submitting the form. If there is no value, then the component validity state will be invalid.
|
|
131
|
+
*/
|
|
132
|
+
required?: boolean;
|
|
65
133
|
}
|
|
66
134
|
|
|
67
135
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
2
|
import { createComponent as t } from "@lit/react";
|
|
3
3
|
import { PieTextarea as a } from "./index.js";
|
|
4
|
-
import { defaultProps as
|
|
4
|
+
import { defaultProps as T, resizeModes as l, sizes as d } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
6
|
import "lit/decorators.js";
|
|
7
|
+
import "lit/directives/if-defined.js";
|
|
8
|
+
import "lit/directives/live.js";
|
|
7
9
|
import "@justeattakeaway/pie-webc-core";
|
|
8
10
|
const r = t({
|
|
9
11
|
displayName: "PieTextarea",
|
|
10
12
|
elementClass: a,
|
|
11
13
|
react: e,
|
|
12
14
|
tagName: "pie-textarea",
|
|
13
|
-
events: {
|
|
14
|
-
|
|
15
|
+
events: {
|
|
16
|
+
onInput: "input",
|
|
17
|
+
// when the textarea value is changed.
|
|
18
|
+
onChange: "change"
|
|
19
|
+
// when the textarea value is changed.
|
|
20
|
+
}
|
|
21
|
+
}), c = r;
|
|
15
22
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
c as PieTextarea,
|
|
24
|
+
T as defaultProps,
|
|
25
|
+
l as resizeModes,
|
|
26
|
+
d as sizes
|
|
20
27
|
};
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -20,12 +20,46 @@ export interface TextareaProps {
|
|
|
20
20
|
* When set to `manual`, the textarea will not resize automatically but can be resized by the user.
|
|
21
21
|
*/
|
|
22
22
|
resize?: typeof resizeModes[number];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The value of the textarea (used as a key/value pair in HTML forms with `name`).
|
|
26
|
+
*/
|
|
27
|
+
value: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The name of the textarea (used as a key/value pair with `value`). This is required in order to work properly with forms.
|
|
31
|
+
*/
|
|
32
|
+
name?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Allows the user to enable or disable autocomplete functionality on the textarea field.
|
|
36
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for more information and values.
|
|
37
|
+
*/
|
|
38
|
+
autocomplete?: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If true, the textarea will be focused on the first render.
|
|
42
|
+
* No more than one element in the document or dialog may have the autofocus attribute. If applied to multiple elements the first one will receive focus.
|
|
43
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) for more information.
|
|
44
|
+
*/
|
|
45
|
+
autoFocus?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* When true, the user cannot edit the control. Not the same as disabled.
|
|
49
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) for more information.
|
|
50
|
+
*/
|
|
51
|
+
readonly?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* If true, the textarea is required to have a value before submitting the form. If there is no value, then the component validity state will be invalid.
|
|
55
|
+
*/
|
|
56
|
+
required?: boolean;
|
|
23
57
|
}
|
|
24
58
|
|
|
25
59
|
/**
|
|
26
60
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
27
61
|
*/
|
|
28
|
-
type DefaultProps = ComponentDefaultProps<TextareaProps
|
|
62
|
+
type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name'| 'autocomplete'>>;
|
|
29
63
|
|
|
30
64
|
/**
|
|
31
65
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -34,4 +68,8 @@ export const defaultProps: DefaultProps = {
|
|
|
34
68
|
disabled: false,
|
|
35
69
|
size: 'medium',
|
|
36
70
|
resize: 'auto',
|
|
71
|
+
value: '',
|
|
72
|
+
autoFocus: false,
|
|
73
|
+
readonly: false,
|
|
74
|
+
required: false,
|
|
37
75
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,9 +2,13 @@ import {
|
|
|
2
2
|
LitElement, html, unsafeCSS, PropertyValues,
|
|
3
3
|
} from 'lit';
|
|
4
4
|
import { property, query } from 'lit/decorators.js';
|
|
5
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
6
|
+
import { live } from 'lit/directives/live.js';
|
|
5
7
|
import throttle from 'lodash.throttle';
|
|
6
8
|
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
validPropertyValues, RtlMixin, defineCustomElement, FormControlMixin, wrapNativeEvent,
|
|
11
|
+
} from '@justeattakeaway/pie-webc-core';
|
|
8
12
|
|
|
9
13
|
import styles from './textarea.scss?inline';
|
|
10
14
|
import {
|
|
@@ -18,10 +22,15 @@ const componentSelector = 'pie-textarea';
|
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* @tagname pie-textarea
|
|
25
|
+
* @event {InputEvent} input - when the textarea value is changed.
|
|
26
|
+
* @event {CustomEvent} change - when the textarea value is changed.
|
|
21
27
|
*/
|
|
22
|
-
export class PieTextarea extends RtlMixin(LitElement) implements TextareaProps {
|
|
28
|
+
export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implements TextareaProps {
|
|
23
29
|
static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
24
30
|
|
|
31
|
+
@property({ type: String })
|
|
32
|
+
public value = defaultProps.value;
|
|
33
|
+
|
|
25
34
|
@property({ type: Boolean, reflect: true })
|
|
26
35
|
public disabled = defaultProps.disabled;
|
|
27
36
|
|
|
@@ -33,6 +42,21 @@ export class PieTextarea extends RtlMixin(LitElement) implements TextareaProps {
|
|
|
33
42
|
@validPropertyValues(componentSelector, resizeModes, defaultProps.resize)
|
|
34
43
|
public resize = defaultProps.resize;
|
|
35
44
|
|
|
45
|
+
@property({ type: Boolean })
|
|
46
|
+
public readonly = defaultProps.readonly;
|
|
47
|
+
|
|
48
|
+
@property({ type: Boolean })
|
|
49
|
+
public autoFocus = defaultProps.autoFocus;
|
|
50
|
+
|
|
51
|
+
@property({ type: Boolean })
|
|
52
|
+
public required = defaultProps.required;
|
|
53
|
+
|
|
54
|
+
@property({ type: String })
|
|
55
|
+
public name?: TextareaProps['name'];
|
|
56
|
+
|
|
57
|
+
@property({ type: String })
|
|
58
|
+
public autocomplete?: TextareaProps['autocomplete'];
|
|
59
|
+
|
|
36
60
|
@query('textarea')
|
|
37
61
|
private _textarea!: HTMLTextAreaElement;
|
|
38
62
|
|
|
@@ -43,14 +67,83 @@ export class PieTextarea extends RtlMixin(LitElement) implements TextareaProps {
|
|
|
43
67
|
}
|
|
44
68
|
}, 100);
|
|
45
69
|
|
|
70
|
+
/**
|
|
71
|
+
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
72
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
|
73
|
+
*/
|
|
74
|
+
public get validity (): ValidityState {
|
|
75
|
+
return (this._textarea as HTMLTextAreaElement).validity;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Called after the disabled state of the element changes,
|
|
80
|
+
* either because the disabled attribute of this element was added or removed;
|
|
81
|
+
* or because the disabled state changed on a <fieldset> that's an ancestor of this element.
|
|
82
|
+
* @param disabled - The latest disabled state of the input.
|
|
83
|
+
*/
|
|
84
|
+
public formDisabledCallback (disabled: boolean): void {
|
|
85
|
+
this.disabled = disabled;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Called when the form that owns this component is reset.
|
|
90
|
+
* Resets the value to the default value.
|
|
91
|
+
*/
|
|
92
|
+
public formResetCallback (): void {
|
|
93
|
+
this.value = defaultProps.value;
|
|
94
|
+
|
|
95
|
+
this._internals.setFormValue(this.value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected firstUpdated (): void {
|
|
99
|
+
this._internals.setFormValue(this.value);
|
|
100
|
+
|
|
101
|
+
this._textarea.addEventListener('keydown', this.handleKeyDown);
|
|
102
|
+
}
|
|
103
|
+
|
|
46
104
|
private handleResize () {
|
|
47
105
|
this._throttledResize();
|
|
48
106
|
}
|
|
49
107
|
|
|
50
|
-
updated (changedProperties: PropertyValues<this>) {
|
|
108
|
+
protected updated (changedProperties: PropertyValues<this>) {
|
|
51
109
|
if (this.resize === 'auto' && (changedProperties.has('resize') || changedProperties.has('size'))) {
|
|
52
110
|
this.handleResize();
|
|
53
111
|
}
|
|
112
|
+
|
|
113
|
+
if (changedProperties.has('value')) {
|
|
114
|
+
this._internals.setFormValue(this.value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Handles data processing in response to the input event. The native input event is left to bubble up.
|
|
120
|
+
* @param event - The input event.
|
|
121
|
+
*/
|
|
122
|
+
private handleInput = (event: InputEvent) => {
|
|
123
|
+
this.value = (event.target as HTMLTextAreaElement).value;
|
|
124
|
+
this._internals.setFormValue(this.value);
|
|
125
|
+
|
|
126
|
+
this.handleResize();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
private handleChange = (event: Event) => {
|
|
130
|
+
// We have to create our own change event because the native one
|
|
131
|
+
// does not penetrate the shadow boundary.
|
|
132
|
+
|
|
133
|
+
// This is because some events set `composed` to `false`.
|
|
134
|
+
// Reference: https://javascript.info/shadow-dom-events#event-composed
|
|
135
|
+
const customChangeEvent = wrapNativeEvent(event);
|
|
136
|
+
this.dispatchEvent(customChangeEvent);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
private handleKeyDown = (event: KeyboardEvent) => {
|
|
140
|
+
if (event.key === 'Enter') {
|
|
141
|
+
event.stopPropagation();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
public disconnectedCallback (): void {
|
|
146
|
+
this._textarea.removeEventListener('keydown', this.handleKeyDown);
|
|
54
147
|
}
|
|
55
148
|
|
|
56
149
|
render () {
|
|
@@ -58,6 +151,12 @@ export class PieTextarea extends RtlMixin(LitElement) implements TextareaProps {
|
|
|
58
151
|
disabled,
|
|
59
152
|
resize,
|
|
60
153
|
size,
|
|
154
|
+
autocomplete,
|
|
155
|
+
autoFocus,
|
|
156
|
+
name,
|
|
157
|
+
readonly,
|
|
158
|
+
value,
|
|
159
|
+
required,
|
|
61
160
|
} = this;
|
|
62
161
|
|
|
63
162
|
return html`
|
|
@@ -67,9 +166,16 @@ export class PieTextarea extends RtlMixin(LitElement) implements TextareaProps {
|
|
|
67
166
|
data-pie-size="${size}"
|
|
68
167
|
data-pie-resize="${resize}">
|
|
69
168
|
<textarea
|
|
70
|
-
|
|
71
|
-
|
|
169
|
+
name=${ifDefined(name)}
|
|
170
|
+
autocomplete=${ifDefined(autocomplete)}
|
|
171
|
+
.value=${live(value)}
|
|
172
|
+
?autofocus=${autoFocus}
|
|
173
|
+
?readonly=${readonly}
|
|
174
|
+
?required=${required}
|
|
72
175
|
?disabled=${disabled}
|
|
176
|
+
@input=${this.handleInput}
|
|
177
|
+
@change=${this.handleChange}
|
|
178
|
+
data-test-id="pie-textarea"
|
|
73
179
|
></textarea>
|
|
74
180
|
</div>`;
|
|
75
181
|
}
|
package/src/react.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createComponent } from '@lit/react';
|
|
2
|
+
import { createComponent, EventName } from '@lit/react';
|
|
3
3
|
import { PieTextarea as PieTextareaLit } from './index';
|
|
4
4
|
import { TextareaProps } from './defs';
|
|
5
5
|
|
|
@@ -10,10 +10,18 @@ const PieTextareaReact = createComponent({
|
|
|
10
10
|
elementClass: PieTextareaLit,
|
|
11
11
|
react: React,
|
|
12
12
|
tagName: 'pie-textarea',
|
|
13
|
-
events: {
|
|
13
|
+
events: {
|
|
14
|
+
onInput: 'input' as EventName<InputEvent>, // when the textarea value is changed.
|
|
15
|
+
onChange: 'change' as EventName<CustomEvent>, // when the textarea value is changed.
|
|
16
|
+
},
|
|
14
17
|
});
|
|
15
18
|
|
|
16
19
|
type ReactBaseType = React.HTMLAttributes<HTMLTextAreaElement>
|
|
17
20
|
|
|
21
|
+
type PieTextareaEvents = {
|
|
22
|
+
onInput?: (event: InputEvent) => void;
|
|
23
|
+
onChange?: (event: CustomEvent) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
18
26
|
export const PieTextarea = PieTextareaReact as React.ForwardRefExoticComponent<React.PropsWithoutRef<TextareaProps>
|
|
19
|
-
& React.RefAttributes<PieTextareaLit> & ReactBaseType>;
|
|
27
|
+
& React.RefAttributes<PieTextareaLit> & PieTextareaEvents & ReactBaseType>;
|