@justeattakeaway/pie-textarea 0.11.1 → 0.13.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/custom-elements.json +1 -51
- package/dist/index.d.ts +1 -14
- package/dist/index.js +156 -177
- package/dist/react.d.ts +1 -14
- package/package.json +2 -2
- package/src/defs.ts +1 -13
- package/src/index.ts +0 -30
package/custom-elements.json
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"type": {
|
|
43
43
|
"text": "DefaultProps"
|
|
44
44
|
},
|
|
45
|
-
"default": "{\n disabled: false,\n size: 'medium',\n resize: 'auto',\n
|
|
45
|
+
"default": "{\n disabled: false,\n size: 'medium',\n resize: 'auto',\n value: '',\n placeholder: '',\n status: 'default',\n autoFocus: false,\n readonly: false,\n required: false,\n}",
|
|
46
46
|
"description": "Default values for optional properties that have default fallback values in the component."
|
|
47
47
|
}
|
|
48
48
|
],
|
|
@@ -133,21 +133,6 @@
|
|
|
133
133
|
"privacy": "public",
|
|
134
134
|
"attribute": "resize"
|
|
135
135
|
},
|
|
136
|
-
{
|
|
137
|
-
"kind": "field",
|
|
138
|
-
"name": "label",
|
|
139
|
-
"privacy": "public",
|
|
140
|
-
"attribute": "label"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
"kind": "field",
|
|
144
|
-
"name": "maxLength",
|
|
145
|
-
"type": {
|
|
146
|
-
"text": "TextareaProps['maxLength']"
|
|
147
|
-
},
|
|
148
|
-
"privacy": "public",
|
|
149
|
-
"attribute": "maxLength"
|
|
150
|
-
},
|
|
151
136
|
{
|
|
152
137
|
"kind": "field",
|
|
153
138
|
"name": "readonly",
|
|
@@ -275,11 +260,6 @@
|
|
|
275
260
|
"name": "handleResize",
|
|
276
261
|
"privacy": "private"
|
|
277
262
|
},
|
|
278
|
-
{
|
|
279
|
-
"kind": "method",
|
|
280
|
-
"name": "restrictInputLength",
|
|
281
|
-
"privacy": "private"
|
|
282
|
-
},
|
|
283
263
|
{
|
|
284
264
|
"kind": "field",
|
|
285
265
|
"name": "handleInput",
|
|
@@ -318,25 +298,6 @@
|
|
|
318
298
|
"name": "handleKeyDown",
|
|
319
299
|
"privacy": "private"
|
|
320
300
|
},
|
|
321
|
-
{
|
|
322
|
-
"kind": "method",
|
|
323
|
-
"name": "renderLabel",
|
|
324
|
-
"parameters": [
|
|
325
|
-
{
|
|
326
|
-
"name": "label",
|
|
327
|
-
"type": {
|
|
328
|
-
"text": "string"
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
"name": "maxLength",
|
|
333
|
-
"optional": true,
|
|
334
|
-
"type": {
|
|
335
|
-
"text": "number"
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
]
|
|
339
|
-
},
|
|
340
301
|
{
|
|
341
302
|
"kind": "method",
|
|
342
303
|
"name": "renderAssistiveText"
|
|
@@ -382,17 +343,6 @@
|
|
|
382
343
|
"name": "resize",
|
|
383
344
|
"fieldName": "resize"
|
|
384
345
|
},
|
|
385
|
-
{
|
|
386
|
-
"name": "label",
|
|
387
|
-
"fieldName": "label"
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
"name": "maxLength",
|
|
391
|
-
"type": {
|
|
392
|
-
"text": "TextareaProps['maxLength']"
|
|
393
|
-
},
|
|
394
|
-
"fieldName": "maxLength"
|
|
395
|
-
},
|
|
396
346
|
{
|
|
397
347
|
"name": "readonly",
|
|
398
348
|
"fieldName": "readonly"
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { TemplateResult } from 'lit-html';
|
|
|
12
12
|
/**
|
|
13
13
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
14
14
|
*/
|
|
15
|
-
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | '
|
|
15
|
+
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue'>>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -35,8 +35,6 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
|
|
|
35
35
|
disabled: boolean;
|
|
36
36
|
size: "small" | "medium" | "large";
|
|
37
37
|
resize: "auto" | "manual";
|
|
38
|
-
label: string;
|
|
39
|
-
maxLength: TextareaProps['maxLength'];
|
|
40
38
|
readonly: boolean;
|
|
41
39
|
autoFocus: boolean;
|
|
42
40
|
required: boolean;
|
|
@@ -67,7 +65,6 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
|
|
|
67
65
|
formResetCallback(): void;
|
|
68
66
|
protected firstUpdated(): void;
|
|
69
67
|
private handleResize;
|
|
70
|
-
private restrictInputLength;
|
|
71
68
|
protected updated(changedProperties: PropertyValues<this>): void;
|
|
72
69
|
/**
|
|
73
70
|
* Handles input events and updates the component's value based on the input event or a provided new value.
|
|
@@ -82,7 +79,6 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
|
|
|
82
79
|
private handleChange;
|
|
83
80
|
private handleKeyDown;
|
|
84
81
|
disconnectedCallback(): void;
|
|
85
|
-
renderLabel(label: string, maxLength?: number): TemplateResult<1> | typeof nothing;
|
|
86
82
|
renderAssistiveText(): TemplateResult<1> | typeof nothing;
|
|
87
83
|
render(): TemplateResult<1>;
|
|
88
84
|
static styles: CSSResult;
|
|
@@ -151,15 +147,6 @@ export declare interface TextareaProps {
|
|
|
151
147
|
* 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.
|
|
152
148
|
*/
|
|
153
149
|
required?: boolean;
|
|
154
|
-
/**
|
|
155
|
-
* The label text for the textarea field.
|
|
156
|
-
*/
|
|
157
|
-
label?: string;
|
|
158
|
-
/**
|
|
159
|
-
* The maximum number of characters allowed in the textarea field.
|
|
160
|
-
* If the `label` property is not set, this property will have no effect.
|
|
161
|
-
*/
|
|
162
|
-
maxLength?: number;
|
|
163
150
|
/**
|
|
164
151
|
* The placeholder text to display when the textarea is empty.
|
|
165
152
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,104 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
1
|
+
import { LitElement as F, nothing as K, html as R, unsafeCSS as P } from "lit";
|
|
2
|
+
import { property as d, query as q } from "lit/decorators.js";
|
|
3
3
|
import { classMap as G } from "lit/directives/class-map.js";
|
|
4
|
-
import { ifDefined as
|
|
4
|
+
import { ifDefined as g } from "lit/directives/if-defined.js";
|
|
5
5
|
import { live as H } from "lit/directives/live.js";
|
|
6
6
|
import "@justeattakeaway/pie-assistive-text";
|
|
7
|
-
import "@justeattakeaway/pie-
|
|
8
|
-
import { FormControlMixin as U, RtlMixin as X, wrapNativeEvent as J, validPropertyValues as C, defineCustomElement as Q } from "@justeattakeaway/pie-webc-core";
|
|
7
|
+
import { FormControlMixin as U, RtlMixin as X, wrapNativeEvent as J, validPropertyValues as w, defineCustomElement as Q } from "@justeattakeaway/pie-webc-core";
|
|
9
8
|
var T = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
10
|
-
function Y(
|
|
11
|
-
return
|
|
9
|
+
function Y(e) {
|
|
10
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
12
11
|
}
|
|
13
|
-
var
|
|
12
|
+
var B = "Expected a function", L = NaN, Z = "[object Symbol]", ee = /^\s+|\s+$/g, te = /^[-+]0x[0-9a-f]+$/i, ae = /^0b[01]+$/i, re = /^0o[0-7]+$/i, ie = parseInt, oe = typeof T == "object" && T && T.Object === Object && T, ne = typeof self == "object" && self && self.Object === Object && self, se = oe || ne || Function("return this")(), le = Object.prototype, de = le.toString, ce = Math.max, ue = Math.min, _ = function() {
|
|
14
13
|
return se.Date.now();
|
|
15
14
|
};
|
|
16
|
-
function
|
|
17
|
-
var
|
|
18
|
-
if (typeof
|
|
19
|
-
throw new TypeError(
|
|
20
|
-
|
|
21
|
-
function
|
|
22
|
-
var
|
|
23
|
-
return
|
|
15
|
+
function pe(e, t, a) {
|
|
16
|
+
var l, i, p, u, s, h, v = 0, k = !1, f = !1, m = !0;
|
|
17
|
+
if (typeof e != "function")
|
|
18
|
+
throw new TypeError(B);
|
|
19
|
+
t = M(t) || 0, S(a) && (k = !!a.leading, f = "maxWait" in a, p = f ? ce(M(a.maxWait) || 0, t) : p, m = "trailing" in a ? !!a.trailing : m);
|
|
20
|
+
function y(r) {
|
|
21
|
+
var x = l, z = i;
|
|
22
|
+
return l = i = void 0, v = r, u = e.apply(z, x), u;
|
|
24
23
|
}
|
|
25
|
-
function
|
|
26
|
-
return
|
|
24
|
+
function D(r) {
|
|
25
|
+
return v = r, s = setTimeout($, t), k ? y(r) : u;
|
|
27
26
|
}
|
|
28
|
-
function
|
|
29
|
-
var
|
|
30
|
-
return
|
|
27
|
+
function V(r) {
|
|
28
|
+
var x = r - h, z = r - v, I = t - x;
|
|
29
|
+
return f ? ue(I, p - z) : I;
|
|
31
30
|
}
|
|
32
|
-
function O(
|
|
33
|
-
var
|
|
34
|
-
return
|
|
31
|
+
function O(r) {
|
|
32
|
+
var x = r - h, z = r - v;
|
|
33
|
+
return h === void 0 || x >= t || x < 0 || f && z >= p;
|
|
35
34
|
}
|
|
36
35
|
function $() {
|
|
37
|
-
var
|
|
38
|
-
if (O(
|
|
39
|
-
return
|
|
40
|
-
|
|
36
|
+
var r = _();
|
|
37
|
+
if (O(r))
|
|
38
|
+
return C(r);
|
|
39
|
+
s = setTimeout($, V(r));
|
|
41
40
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
41
|
+
function C(r) {
|
|
42
|
+
return s = void 0, m && l ? y(r) : (l = i = void 0, u);
|
|
44
43
|
}
|
|
45
44
|
function A() {
|
|
46
|
-
|
|
45
|
+
s !== void 0 && clearTimeout(s), v = 0, l = h = i = s = void 0;
|
|
47
46
|
}
|
|
48
|
-
function
|
|
49
|
-
return
|
|
47
|
+
function N() {
|
|
48
|
+
return s === void 0 ? u : C(_());
|
|
50
49
|
}
|
|
51
|
-
function
|
|
52
|
-
var
|
|
53
|
-
if (
|
|
54
|
-
if (
|
|
55
|
-
return
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
50
|
+
function E() {
|
|
51
|
+
var r = _(), x = O(r);
|
|
52
|
+
if (l = arguments, i = this, h = r, x) {
|
|
53
|
+
if (s === void 0)
|
|
54
|
+
return D(h);
|
|
55
|
+
if (f)
|
|
56
|
+
return s = setTimeout($, t), y(h);
|
|
58
57
|
}
|
|
59
|
-
return
|
|
58
|
+
return s === void 0 && (s = setTimeout($, t)), u;
|
|
60
59
|
}
|
|
61
|
-
return
|
|
60
|
+
return E.cancel = A, E.flush = N, E;
|
|
62
61
|
}
|
|
63
|
-
function
|
|
64
|
-
var
|
|
65
|
-
if (typeof
|
|
66
|
-
throw new TypeError(
|
|
67
|
-
return S(a) && (
|
|
68
|
-
leading:
|
|
69
|
-
maxWait:
|
|
70
|
-
trailing:
|
|
62
|
+
function he(e, t, a) {
|
|
63
|
+
var l = !0, i = !0;
|
|
64
|
+
if (typeof e != "function")
|
|
65
|
+
throw new TypeError(B);
|
|
66
|
+
return S(a) && (l = "leading" in a ? !!a.leading : l, i = "trailing" in a ? !!a.trailing : i), pe(e, t, {
|
|
67
|
+
leading: l,
|
|
68
|
+
maxWait: t,
|
|
69
|
+
trailing: i
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
|
-
function S(
|
|
74
|
-
var
|
|
75
|
-
return !!
|
|
72
|
+
function S(e) {
|
|
73
|
+
var t = typeof e;
|
|
74
|
+
return !!e && (t == "object" || t == "function");
|
|
76
75
|
}
|
|
77
|
-
function fe(
|
|
78
|
-
return !!
|
|
76
|
+
function fe(e) {
|
|
77
|
+
return !!e && typeof e == "object";
|
|
79
78
|
}
|
|
80
|
-
function xe(
|
|
81
|
-
return typeof
|
|
79
|
+
function xe(e) {
|
|
80
|
+
return typeof e == "symbol" || fe(e) && de.call(e) == Z;
|
|
82
81
|
}
|
|
83
|
-
function
|
|
84
|
-
if (typeof
|
|
85
|
-
return
|
|
86
|
-
if (xe(
|
|
87
|
-
return
|
|
88
|
-
if (S(
|
|
89
|
-
var
|
|
90
|
-
|
|
82
|
+
function M(e) {
|
|
83
|
+
if (typeof e == "number")
|
|
84
|
+
return e;
|
|
85
|
+
if (xe(e))
|
|
86
|
+
return L;
|
|
87
|
+
if (S(e)) {
|
|
88
|
+
var t = typeof e.valueOf == "function" ? e.valueOf() : e;
|
|
89
|
+
e = S(t) ? t + "" : t;
|
|
91
90
|
}
|
|
92
|
-
if (typeof
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
var a = ae.test(
|
|
96
|
-
return a || re.test(
|
|
91
|
+
if (typeof e != "string")
|
|
92
|
+
return e === 0 ? e : +e;
|
|
93
|
+
e = e.replace(ee, "");
|
|
94
|
+
var a = ae.test(e);
|
|
95
|
+
return a || re.test(e) ? ie(e.slice(2), a ? 2 : 8) : te.test(e) ? L : +e;
|
|
97
96
|
}
|
|
98
|
-
var ve =
|
|
97
|
+
var ve = he;
|
|
99
98
|
const ge = /* @__PURE__ */ Y(ve), be = "*,*: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-c);--textarea-padding-block: var(--dt-spacing-b);--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-placeholder-color: var(--dt-color-content-placeholder);--textarea-height: calc((var(--textarea-line-height) * 2) + (var(--textarea-padding-block) * 2));line-height:0;padding:var(--dt-spacing-a);border:var(--textarea-border-thickness) solid var(--textarea-border-color);background-color:var(--textarea-background-color);border-radius:var(--dt-radius-rounded-c);inline-size:100%}.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:none;background-color:var(--textarea-background-color);color:var(--textarea-content-color);block-size:var(--textarea-height);max-block-size:var(--textarea-max-height);min-block-size:var(--textarea-min-height);inline-size:100%;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:focus{box-shadow:none;outline:none}.c-textareaWrapper textarea::placeholder{color:var(--textarea-placeholder-color);opacity:1}.c-textareaWrapper.c-textarea--readonly{--textarea-background-color: var(--dt-color-container-subtle);--textarea-border-color: var(--dt-color-interactive-form)}.c-textareaWrapper.c-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);--textarea-placeholder-color: var(--dt-color-content-disabled)}@media (hover: hover){.c-textareaWrapper:hover:not(.c-textarea--disabled,.c-textarea--readonly){--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:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-textareaWrapper.c-textarea--large{--textarea-padding-block: var(--dt-spacing-c)}.c-textareaWrapper.c-textarea--small{--textarea-padding-block: var(--dt-spacing-a)}.c-textareaWrapper.c-textarea--resize-manual{--textarea-resize: vertical;--textarea-min-height: calc((var(--textarea-line-height) * 1) + (var(--textarea-padding-block) * 2))}@media (pointer: coarse){.c-textareaWrapper.c-textarea--resize-manual{--textarea-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2));--textarea-min-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2));--textarea-max-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2));--textarea-resize: none}}.c-textareaWrapper.c-textarea--resize-auto{--textarea-max-height: calc((var(--textarea-line-height) * 6) + (var(--textarea-padding-block) * 2));--textarea-min-height: var(--textarea-height)}.c-textareaWrapper.c-textarea--error{--textarea-border-color: var(--dt-color-support-error)}", me = ["small", "medium", "large"], ye = ["auto", "manual"], ze = ["default", "success", "error"], c = {
|
|
100
99
|
disabled: !1,
|
|
101
100
|
size: "medium",
|
|
102
101
|
resize: "auto",
|
|
103
|
-
label: "",
|
|
104
102
|
value: "",
|
|
105
103
|
placeholder: "",
|
|
106
104
|
status: "default",
|
|
@@ -108,22 +106,22 @@ const ge = /* @__PURE__ */ Y(ve), be = "*,*:after,*:before{box-sizing:inherit}.c
|
|
|
108
106
|
readonly: !1,
|
|
109
107
|
required: !1
|
|
110
108
|
};
|
|
111
|
-
var ke = Object.defineProperty, n = (
|
|
112
|
-
for (var
|
|
113
|
-
(u =
|
|
114
|
-
return
|
|
109
|
+
var ke = Object.defineProperty, n = (e, t, a, l) => {
|
|
110
|
+
for (var i = void 0, p = e.length - 1, u; p >= 0; p--)
|
|
111
|
+
(u = e[p]) && (i = u(t, a, i) || i);
|
|
112
|
+
return i && ke(t, a, i), i;
|
|
115
113
|
};
|
|
116
|
-
const
|
|
114
|
+
const b = "pie-textarea", j = "assistive-text", W = class W extends U(X(F)) {
|
|
117
115
|
constructor() {
|
|
118
|
-
super(...arguments), this.value = c.value, this.disabled = c.disabled, this.size = c.size, this.resize = c.resize, this.
|
|
116
|
+
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.status = c.status, this._throttledResize = ge(() => {
|
|
119
117
|
this.resize === "auto" && (this._textarea.style.height = "auto", this._textarea.style.height = `${this._textarea.scrollHeight}px`);
|
|
120
|
-
}, 100), this.handleInput = (
|
|
121
|
-
|
|
122
|
-
}, this.handleChange = (
|
|
123
|
-
const a = J(
|
|
118
|
+
}, 100), this.handleInput = (t, a) => {
|
|
119
|
+
t ? this.value = t.target.value : a && (this.value = a), this._internals.setFormValue(this.value), this.handleResize();
|
|
120
|
+
}, this.handleChange = (t) => {
|
|
121
|
+
const a = J(t);
|
|
124
122
|
this.dispatchEvent(a);
|
|
125
|
-
}, this.handleKeyDown = (
|
|
126
|
-
|
|
123
|
+
}, this.handleKeyDown = (t) => {
|
|
124
|
+
t.key === "Enter" && t.stopPropagation();
|
|
127
125
|
};
|
|
128
126
|
}
|
|
129
127
|
/**
|
|
@@ -139,8 +137,8 @@ const m = "pie-textarea", I = "assistive-text", W = class W extends U(X(M)) {
|
|
|
139
137
|
* or because the disabled state changed on a <fieldset> that's an ancestor of this element.
|
|
140
138
|
* @param disabled - The latest disabled state of the input.
|
|
141
139
|
*/
|
|
142
|
-
formDisabledCallback(
|
|
143
|
-
this.disabled =
|
|
140
|
+
formDisabledCallback(t) {
|
|
141
|
+
this.disabled = t;
|
|
144
142
|
}
|
|
145
143
|
/**
|
|
146
144
|
* Called when the form that owns this component is reset.
|
|
@@ -150,80 +148,67 @@ const m = "pie-textarea", I = "assistive-text", W = class W extends U(X(M)) {
|
|
|
150
148
|
this.value = this.defaultValue ?? c.value, this._internals.setFormValue(this.value);
|
|
151
149
|
}
|
|
152
150
|
firstUpdated() {
|
|
153
|
-
this.
|
|
151
|
+
this._internals.setFormValue(this.value), window.addEventListener("resize", () => this.handleResize()), this._textarea.addEventListener("keydown", this.handleKeyDown);
|
|
154
152
|
}
|
|
155
153
|
handleResize() {
|
|
156
154
|
this._throttledResize();
|
|
157
155
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const e = this.value.slice(0, this.maxLength);
|
|
161
|
-
this._textarea.value = e, this.value = e;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
updated(e) {
|
|
165
|
-
e.has("value") && this.handleInput(null, this.value), this.resize === "auto" && (e.has("resize") || e.has("size")) && this.handleResize();
|
|
156
|
+
updated(t) {
|
|
157
|
+
t.has("value") && this.handleInput(null, this.value), this.resize === "auto" && (t.has("resize") || t.has("size")) && this.handleResize();
|
|
166
158
|
}
|
|
167
159
|
disconnectedCallback() {
|
|
168
160
|
this._textarea.removeEventListener("keydown", this.handleKeyDown), window.removeEventListener("resize", () => this.handleResize());
|
|
169
161
|
}
|
|
170
|
-
renderLabel(e, a) {
|
|
171
|
-
const s = a ? `${this.value.length}/${a}` : void 0;
|
|
172
|
-
return e != null && e.length ? j`<pie-form-label for="${m}" trailing=${b(s)}>${e}</pie-form-label>` : q;
|
|
173
|
-
}
|
|
174
162
|
renderAssistiveText() {
|
|
175
|
-
return this.assistiveText ?
|
|
163
|
+
return this.assistiveText ? R`
|
|
176
164
|
<pie-assistive-text
|
|
177
|
-
id="${
|
|
178
|
-
variant=${
|
|
165
|
+
id="${j}"
|
|
166
|
+
variant=${g(this.status)}
|
|
179
167
|
data-test-id="pie-textarea-assistive-text">
|
|
180
168
|
${this.assistiveText}
|
|
181
169
|
</pie-assistive-text>
|
|
182
|
-
` :
|
|
170
|
+
` : K;
|
|
183
171
|
}
|
|
184
172
|
render() {
|
|
185
173
|
const {
|
|
186
|
-
disabled:
|
|
174
|
+
disabled: t,
|
|
187
175
|
resize: a,
|
|
188
|
-
size:
|
|
189
|
-
autocomplete:
|
|
190
|
-
autoFocus:
|
|
176
|
+
size: l,
|
|
177
|
+
autocomplete: i,
|
|
178
|
+
autoFocus: p,
|
|
191
179
|
name: u,
|
|
192
|
-
readonly:
|
|
193
|
-
placeholder:
|
|
194
|
-
value:
|
|
180
|
+
readonly: s,
|
|
181
|
+
placeholder: h,
|
|
182
|
+
value: v,
|
|
195
183
|
required: k,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
assistiveText: _
|
|
200
|
-
} = this, E = {
|
|
184
|
+
status: f,
|
|
185
|
+
assistiveText: m
|
|
186
|
+
} = this, y = {
|
|
201
187
|
"c-textareaWrapper": !0,
|
|
202
|
-
"c-textarea--disabled":
|
|
203
|
-
"c-textarea--readonly":
|
|
204
|
-
"c-textarea--error":
|
|
188
|
+
"c-textarea--disabled": t,
|
|
189
|
+
"c-textarea--readonly": s,
|
|
190
|
+
"c-textarea--error": f === "error",
|
|
205
191
|
[`c-textarea--resize-${a}`]: !0,
|
|
206
|
-
[`c-textarea--${
|
|
192
|
+
[`c-textarea--${l}`]: !0
|
|
207
193
|
};
|
|
208
|
-
return
|
|
209
|
-
${this.renderLabel(v, y)}
|
|
194
|
+
return R`<div>
|
|
210
195
|
<div
|
|
211
|
-
class="${G(
|
|
196
|
+
class="${G(y)}"
|
|
212
197
|
data-test-id="pie-textarea-wrapper">
|
|
213
198
|
<textarea
|
|
214
|
-
id="${
|
|
215
|
-
data-test-id="${
|
|
216
|
-
name=${
|
|
217
|
-
autocomplete=${
|
|
218
|
-
placeholder=${
|
|
219
|
-
.value=${H(
|
|
220
|
-
?autofocus=${
|
|
221
|
-
?readonly=${
|
|
199
|
+
id="${b}"
|
|
200
|
+
data-test-id="${b}"
|
|
201
|
+
name=${g(u)}
|
|
202
|
+
autocomplete=${g(i)}
|
|
203
|
+
placeholder=${g(h)}
|
|
204
|
+
.value=${H(v)}
|
|
205
|
+
?autofocus=${p}
|
|
206
|
+
?readonly=${s}
|
|
222
207
|
?required=${k}
|
|
223
|
-
?disabled=${
|
|
224
|
-
aria-describedby=${
|
|
225
|
-
aria-invalid=${
|
|
226
|
-
aria-errormessage="${
|
|
208
|
+
?disabled=${t}
|
|
209
|
+
aria-describedby=${g(m ? j : void 0)}
|
|
210
|
+
aria-invalid=${f === "error" ? "true" : "false"}
|
|
211
|
+
aria-errormessage="${g(f === "error" ? j : void 0)}"
|
|
227
212
|
@input=${this.handleInput}
|
|
228
213
|
@change=${this.handleChange}
|
|
229
214
|
></textarea>
|
|
@@ -232,65 +217,59 @@ const m = "pie-textarea", I = "assistive-text", W = class W extends U(X(M)) {
|
|
|
232
217
|
</div>`;
|
|
233
218
|
}
|
|
234
219
|
};
|
|
235
|
-
W.shadowRootOptions = { ...
|
|
236
|
-
let
|
|
237
|
-
n([
|
|
238
|
-
l({ type: String })
|
|
239
|
-
], r.prototype, "value");
|
|
240
|
-
n([
|
|
241
|
-
l({ type: String })
|
|
242
|
-
], r.prototype, "defaultValue");
|
|
220
|
+
W.shadowRootOptions = { ...F.shadowRootOptions, delegatesFocus: !0 }, W.styles = P(be);
|
|
221
|
+
let o = W;
|
|
243
222
|
n([
|
|
244
|
-
|
|
245
|
-
],
|
|
223
|
+
d({ type: String })
|
|
224
|
+
], o.prototype, "value");
|
|
246
225
|
n([
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
], r.prototype, "size");
|
|
226
|
+
d({ type: String })
|
|
227
|
+
], o.prototype, "defaultValue");
|
|
250
228
|
n([
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
], r.prototype, "resize");
|
|
229
|
+
d({ type: Boolean, reflect: !0 })
|
|
230
|
+
], o.prototype, "disabled");
|
|
254
231
|
n([
|
|
255
|
-
|
|
256
|
-
|
|
232
|
+
d({ type: String }),
|
|
233
|
+
w(b, me, c.size)
|
|
234
|
+
], o.prototype, "size");
|
|
257
235
|
n([
|
|
258
|
-
|
|
259
|
-
|
|
236
|
+
d({ type: String }),
|
|
237
|
+
w(b, ye, c.resize)
|
|
238
|
+
], o.prototype, "resize");
|
|
260
239
|
n([
|
|
261
|
-
|
|
262
|
-
],
|
|
240
|
+
d({ type: Boolean })
|
|
241
|
+
], o.prototype, "readonly");
|
|
263
242
|
n([
|
|
264
|
-
|
|
265
|
-
],
|
|
243
|
+
d({ type: Boolean })
|
|
244
|
+
], o.prototype, "autoFocus");
|
|
266
245
|
n([
|
|
267
|
-
|
|
268
|
-
],
|
|
246
|
+
d({ type: Boolean })
|
|
247
|
+
], o.prototype, "required");
|
|
269
248
|
n([
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
],
|
|
249
|
+
d({ type: String }),
|
|
250
|
+
w(b, ze, c.status)
|
|
251
|
+
], o.prototype, "status");
|
|
273
252
|
n([
|
|
274
|
-
|
|
275
|
-
],
|
|
253
|
+
d({ type: String })
|
|
254
|
+
], o.prototype, "assistiveText");
|
|
276
255
|
n([
|
|
277
|
-
|
|
278
|
-
],
|
|
256
|
+
d({ type: String })
|
|
257
|
+
], o.prototype, "name");
|
|
279
258
|
n([
|
|
280
|
-
|
|
281
|
-
],
|
|
259
|
+
d({ type: String })
|
|
260
|
+
], o.prototype, "autocomplete");
|
|
282
261
|
n([
|
|
283
|
-
|
|
284
|
-
],
|
|
262
|
+
d({ type: String })
|
|
263
|
+
], o.prototype, "placeholder");
|
|
285
264
|
n([
|
|
286
|
-
|
|
287
|
-
],
|
|
265
|
+
q("textarea")
|
|
266
|
+
], o.prototype, "_textarea");
|
|
288
267
|
n([
|
|
289
|
-
|
|
290
|
-
],
|
|
291
|
-
Q(
|
|
268
|
+
q("textarea")
|
|
269
|
+
], o.prototype, "focusTarget");
|
|
270
|
+
Q(b, o);
|
|
292
271
|
export {
|
|
293
|
-
|
|
272
|
+
o as PieTextarea,
|
|
294
273
|
c as defaultProps,
|
|
295
274
|
ye as resizeModes,
|
|
296
275
|
me as sizes,
|
package/dist/react.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { TemplateResult } from 'lit-html';
|
|
|
13
13
|
/**
|
|
14
14
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
15
15
|
*/
|
|
16
|
-
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | '
|
|
16
|
+
declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue'>>;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -38,8 +38,6 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
|
|
|
38
38
|
disabled: boolean;
|
|
39
39
|
size: "small" | "medium" | "large";
|
|
40
40
|
resize: "auto" | "manual";
|
|
41
|
-
label: string;
|
|
42
|
-
maxLength: TextareaProps['maxLength'];
|
|
43
41
|
readonly: boolean;
|
|
44
42
|
autoFocus: boolean;
|
|
45
43
|
required: boolean;
|
|
@@ -70,7 +68,6 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
|
|
|
70
68
|
formResetCallback(): void;
|
|
71
69
|
protected firstUpdated(): void;
|
|
72
70
|
private handleResize;
|
|
73
|
-
private restrictInputLength;
|
|
74
71
|
protected updated(changedProperties: PropertyValues<this>): void;
|
|
75
72
|
/**
|
|
76
73
|
* Handles input events and updates the component's value based on the input event or a provided new value.
|
|
@@ -85,7 +82,6 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
|
|
|
85
82
|
private handleChange;
|
|
86
83
|
private handleKeyDown;
|
|
87
84
|
disconnectedCallback(): void;
|
|
88
|
-
renderLabel(label: string, maxLength?: number): TemplateResult<1> | typeof nothing;
|
|
89
85
|
renderAssistiveText(): TemplateResult<1> | typeof nothing;
|
|
90
86
|
render(): TemplateResult<1>;
|
|
91
87
|
static styles: CSSResult;
|
|
@@ -161,15 +157,6 @@ export declare interface TextareaProps {
|
|
|
161
157
|
* 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.
|
|
162
158
|
*/
|
|
163
159
|
required?: boolean;
|
|
164
|
-
/**
|
|
165
|
-
* The label text for the textarea field.
|
|
166
|
-
*/
|
|
167
|
-
label?: string;
|
|
168
|
-
/**
|
|
169
|
-
* The maximum number of characters allowed in the textarea field.
|
|
170
|
-
* If the `label` property is not set, this property will have no effect.
|
|
171
|
-
*/
|
|
172
|
-
maxLength?: number;
|
|
173
160
|
/**
|
|
174
161
|
* The placeholder text to display when the textarea is empty.
|
|
175
162
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-textarea",
|
|
3
3
|
"description": "PIE Design System Textarea built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@justeattakeaway/pie-
|
|
45
|
+
"@justeattakeaway/pie-assistive-text": "0.8.0",
|
|
46
46
|
"@justeattakeaway/pie-webc-core": "0.24.2",
|
|
47
47
|
"lodash.throttle": "4.1.1"
|
|
48
48
|
},
|
package/src/defs.ts
CHANGED
|
@@ -71,17 +71,6 @@ export interface TextareaProps {
|
|
|
71
71
|
*/
|
|
72
72
|
required?: boolean;
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* The label text for the textarea field.
|
|
76
|
-
*/
|
|
77
|
-
label?: string;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The maximum number of characters allowed in the textarea field.
|
|
81
|
-
* If the `label` property is not set, this property will have no effect.
|
|
82
|
-
*/
|
|
83
|
-
maxLength?: number;
|
|
84
|
-
|
|
85
74
|
/**
|
|
86
75
|
* The placeholder text to display when the textarea is empty.
|
|
87
76
|
*/
|
|
@@ -91,7 +80,7 @@ export interface TextareaProps {
|
|
|
91
80
|
/**
|
|
92
81
|
* The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
|
|
93
82
|
*/
|
|
94
|
-
type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | '
|
|
83
|
+
type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue'>>;
|
|
95
84
|
|
|
96
85
|
/**
|
|
97
86
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -100,7 +89,6 @@ export const defaultProps: DefaultProps = {
|
|
|
100
89
|
disabled: false,
|
|
101
90
|
size: 'medium',
|
|
102
91
|
resize: 'auto',
|
|
103
|
-
label: '',
|
|
104
92
|
value: '',
|
|
105
93
|
placeholder: '',
|
|
106
94
|
status: 'default',
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { live } from 'lit/directives/live.js';
|
|
|
8
8
|
import throttle from 'lodash.throttle';
|
|
9
9
|
|
|
10
10
|
import '@justeattakeaway/pie-assistive-text';
|
|
11
|
-
import '@justeattakeaway/pie-form-label';
|
|
12
11
|
import {
|
|
13
12
|
validPropertyValues, RtlMixin, defineCustomElement, FormControlMixin, wrapNativeEvent, type PIEInputElement,
|
|
14
13
|
} from '@justeattakeaway/pie-webc-core';
|
|
@@ -49,12 +48,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
49
48
|
@validPropertyValues(componentSelector, resizeModes, defaultProps.resize)
|
|
50
49
|
public resize = defaultProps.resize;
|
|
51
50
|
|
|
52
|
-
@property({ type: String })
|
|
53
|
-
public label = defaultProps.label;
|
|
54
|
-
|
|
55
|
-
@property({ type: Number })
|
|
56
|
-
public maxLength: TextareaProps['maxLength'];
|
|
57
|
-
|
|
58
51
|
@property({ type: Boolean })
|
|
59
52
|
public readonly = defaultProps.readonly;
|
|
60
53
|
|
|
@@ -122,7 +115,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
122
115
|
}
|
|
123
116
|
|
|
124
117
|
protected firstUpdated (): void {
|
|
125
|
-
this.restrictInputLength();
|
|
126
118
|
this._internals.setFormValue(this.value);
|
|
127
119
|
|
|
128
120
|
window.addEventListener('resize', () => this.handleResize());
|
|
@@ -133,16 +125,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
133
125
|
this._throttledResize();
|
|
134
126
|
}
|
|
135
127
|
|
|
136
|
-
private restrictInputLength () {
|
|
137
|
-
if (this.label.length && this.maxLength && this.value.length > this.maxLength) {
|
|
138
|
-
const trimmedValue = this.value.slice(0, this.maxLength);
|
|
139
|
-
// Ensures that the internal text area is correctly trimmed and synced with our value.
|
|
140
|
-
// The live() directive does not solve this for us.
|
|
141
|
-
this._textarea.value = trimmedValue;
|
|
142
|
-
this.value = trimmedValue;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
128
|
protected updated (changedProperties: PropertyValues<this>) {
|
|
147
129
|
if (changedProperties.has('value')) {
|
|
148
130
|
this.handleInput(null, this.value);
|
|
@@ -169,7 +151,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
169
151
|
this.value = newValue;
|
|
170
152
|
}
|
|
171
153
|
|
|
172
|
-
this.restrictInputLength();
|
|
173
154
|
this._internals.setFormValue(this.value);
|
|
174
155
|
|
|
175
156
|
this.handleResize();
|
|
@@ -196,14 +177,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
196
177
|
window.removeEventListener('resize', () => this.handleResize());
|
|
197
178
|
}
|
|
198
179
|
|
|
199
|
-
renderLabel (label: string, maxLength?: number) {
|
|
200
|
-
const characterCount = maxLength ? `${this.value.length}/${maxLength}` : undefined;
|
|
201
|
-
|
|
202
|
-
return label?.length
|
|
203
|
-
? html`<pie-form-label for="${componentSelector}" trailing=${ifDefined(characterCount)}>${label}</pie-form-label>`
|
|
204
|
-
: nothing;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
180
|
renderAssistiveText () {
|
|
208
181
|
if (!this.assistiveText) {
|
|
209
182
|
return nothing;
|
|
@@ -231,8 +204,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
231
204
|
placeholder,
|
|
232
205
|
value,
|
|
233
206
|
required,
|
|
234
|
-
label,
|
|
235
|
-
maxLength,
|
|
236
207
|
status,
|
|
237
208
|
assistiveText,
|
|
238
209
|
} = this;
|
|
@@ -247,7 +218,6 @@ export class PieTextarea extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
247
218
|
};
|
|
248
219
|
|
|
249
220
|
return html`<div>
|
|
250
|
-
${this.renderLabel(label, maxLength)}
|
|
251
221
|
<div
|
|
252
222
|
class="${classMap(classes)}"
|
|
253
223
|
data-test-id="pie-textarea-wrapper">
|