@justeattakeaway/pie-textarea 0.21.2 → 0.23.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 CHANGED
@@ -17,6 +17,7 @@
17
17
  - [Slots](#slots)
18
18
  - [CSS Variables](#css-variables)
19
19
  - [Events](#events)
20
+ - [Methods](#methods)
20
21
  - [Forms Usage](#forms-usage)
21
22
  - [Validation](#validation)
22
23
  - [Example](#example)
@@ -38,6 +39,7 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
38
39
  ### Properties
39
40
  | Prop | Options | Description | Default |
40
41
  |----------------|--------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
42
+ | `aria` | `{ label?: string }` | ARIA attributes for the textarea. Offers `label` — use it when no visible label is associated with the textarea. | `undefined` |
41
43
  | `assistiveText`| `string` | Allows assistive text to be displayed below the textarea. Must be provided if using a non-default status. | `undefined` |
42
44
  | `autocomplete` | `string` | Allows enabling or disabling autocomplete. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for values. | `undefined` |
43
45
  | `autoFocus` | `true`, `false` | If true, focuses the textarea on first render. Only one element should have `autofocus`. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus). | `false` |
@@ -66,6 +68,11 @@ This component does not expose any CSS variables for style overrides.
66
68
  | `change` | Fires when the textarea loses focus after the value has been changed. |
67
69
  | `input` | Fires when the textarea value is changed. |
68
70
 
71
+ ### Methods
72
+ | Method | Parameters | Description | Returns |
73
+ |--------|------------|-------------|---------|
74
+ | `setSelectionRange` | `selectionStart: number`, `selectionEnd: number`, `selectionDirection?: "forward" | "backward" | "none"` | Sets the selected text range on the underlying native textarea element. | `void` |
75
+
69
76
  ## Forms Usage
70
77
  It is essential that when using the textarea inside the form, you provide a `name` attribute. HTML forms create key/value pairs for textarea data based on the `name` attribute, which is crucial for native form submission.
71
78
 
@@ -203,6 +203,15 @@
203
203
  "privacy": "public",
204
204
  "attribute": "rows"
205
205
  },
206
+ {
207
+ "kind": "field",
208
+ "name": "aria",
209
+ "type": {
210
+ "text": "TextareaProps['aria']"
211
+ },
212
+ "privacy": "public",
213
+ "attribute": "aria"
214
+ },
206
215
  {
207
216
  "kind": "field",
208
217
  "name": "_textarea",
@@ -262,6 +271,38 @@
262
271
  ],
263
272
  "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."
264
273
  },
274
+ {
275
+ "kind": "method",
276
+ "name": "setSelectionRange",
277
+ "privacy": "public",
278
+ "return": {
279
+ "type": {
280
+ "text": "void"
281
+ }
282
+ },
283
+ "parameters": [
284
+ {
285
+ "name": "selectionStart",
286
+ "type": {
287
+ "text": "number"
288
+ }
289
+ },
290
+ {
291
+ "name": "selectionEnd",
292
+ "type": {
293
+ "text": "number"
294
+ }
295
+ },
296
+ {
297
+ "name": "selectionDirection",
298
+ "default": "'none'",
299
+ "type": {
300
+ "text": "'forward' | 'backward' | 'none'"
301
+ }
302
+ }
303
+ ],
304
+ "description": "Sets the selected text range on the underlying native textarea."
305
+ },
265
306
  {
266
307
  "kind": "method",
267
308
  "name": "formResetCallback",
@@ -419,6 +460,13 @@
419
460
  "text": "TextareaProps['rows']"
420
461
  },
421
462
  "fieldName": "rows"
463
+ },
464
+ {
465
+ "name": "aria",
466
+ "type": {
467
+ "text": "TextareaProps['aria']"
468
+ },
469
+ "fieldName": "aria"
422
470
  }
423
471
  ],
424
472
  "mixins": [
package/dist/index.d.ts CHANGED
@@ -8,10 +8,17 @@ import { PropertyValues } from 'lit';
8
8
  import { RTLInterface } from '@justeattakeaway/pie-webc-core';
9
9
  import { TemplateResult } from 'lit-html';
10
10
 
11
+ declare type AriaProps = {
12
+ /**
13
+ * Provides an accessible label for the textarea. Should be used when no visible label is associated with the textarea.
14
+ */
15
+ label?: string;
16
+ };
17
+
11
18
  /**
12
19
  * The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
13
20
  */
14
- declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows'>>;
21
+ declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows' | 'aria'>>;
15
22
 
16
23
  /**
17
24
  * Default values for optional properties that have default fallback values in the component.
@@ -39,6 +46,7 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
39
46
  placeholder: TextareaProps['placeholder'];
40
47
  maxlength: TextareaProps['maxlength'];
41
48
  rows: TextareaProps['rows'];
49
+ aria: TextareaProps['aria'];
42
50
  private _textarea;
43
51
  focusTarget: HTMLElement;
44
52
  private _abortController;
@@ -59,6 +67,10 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
59
67
  * @param disabled - The latest disabled state of the input.
60
68
  */
61
69
  formDisabledCallback(disabled: boolean): void;
70
+ /**
71
+ * Sets the selected text range on the underlying native textarea.
72
+ */
73
+ setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: 'forward' | 'backward' | 'none'): void;
62
74
  /**
63
75
  * Called when the form that owns this component is reset.
64
76
  * Resets the value to the default value.
@@ -91,6 +103,10 @@ export declare const sizes: readonly ["small", "medium", "large"];
91
103
  export declare const statusTypes: readonly ["default", "success", "error"];
92
104
 
93
105
  export declare interface TextareaProps {
106
+ /**
107
+ * ARIA attributes for the textarea.
108
+ */
109
+ aria?: AriaProps;
94
110
  /**
95
111
  * Same as the HTML disabled attribute - indicates whether the textarea is disabled.
96
112
  */
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import { LitElement as de, html as Y, unsafeCSS as ce } from "lit";
2
2
  import { property as s, query as ee } from "lit/decorators.js";
3
3
  import { classMap as ue } from "lit/directives/class-map.js";
4
- import { ifDefined as g } from "lit/directives/if-defined.js";
4
+ import { ifDefined as f } from "lit/directives/if-defined.js";
5
5
  import { live as pe } from "lit/directives/live.js";
6
6
  import "@justeattakeaway/pie-assistive-text";
7
7
  import { FormControlMixin as he, RtlMixin as xe, DelegatesFocusMixin as fe, wrapNativeEvent as ve, validPropertyValues as U, safeCustomElement as ge } from "@justeattakeaway/pie-webc-core";
8
- const O = class O extends de {
8
+ const I = class I extends de {
9
9
  willUpdate() {
10
- this.getAttribute("v") || this.setAttribute("v", O.v);
10
+ this.getAttribute("v") || this.setAttribute("v", I.v);
11
11
  }
12
12
  };
13
- O.v = "0.21.2";
14
- let P = O;
15
- var j = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
13
+ I.v = "0.23.0";
14
+ let P = I;
15
+ var E = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
16
16
  function be(e) {
17
17
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
18
18
  }
@@ -20,92 +20,92 @@ var V, Z;
20
20
  function me() {
21
21
  if (Z) return V;
22
22
  Z = 1;
23
- var e = "Expected a function", l = NaN, b = "[object Symbol]", x = /^\s+|\s+$/g, c = /^[-+]0x[0-9a-f]+$/i, m = /^0b[01]+$/i, f = /^0o[0-7]+$/i, E = parseInt, I = typeof j == "object" && j && j.Object === Object && j, F = typeof self == "object" && self && self.Object === Object && self, k = I || F || Function("return this")(), R = Object.prototype, L = R.toString, M = Math.max, q = Math.min, D = function() {
23
+ var e = "Expected a function", n = NaN, h = "[object Symbol]", v = /^\s+|\s+$/g, c = /^[-+]0x[0-9a-f]+$/i, m = /^0b[01]+$/i, g = /^0o[0-7]+$/i, F = parseInt, R = typeof E == "object" && E && E.Object === Object && E, L = typeof self == "object" && self && self.Object === Object && self, k = R || L || Function("return this")(), M = Object.prototype, q = M.toString, D = Math.max, $ = Math.min, _ = function() {
24
24
  return k.Date.now();
25
25
  };
26
- function te(t, i, n) {
27
- var p, h, W, z, u, y, $ = 0, K = !1, _ = !1, A = !0;
26
+ function te(t, o, l) {
27
+ var p, x, j, z, u, y, T = 0, K = !1, C = !1, A = !0;
28
28
  if (typeof t != "function")
29
29
  throw new TypeError(e);
30
- i = G(i) || 0, w(n) && (K = !!n.leading, _ = "maxWait" in n, W = _ ? M(G(n.maxWait) || 0, i) : W, A = "trailing" in n ? !!n.trailing : A);
31
- function B(a) {
32
- var v = p, T = h;
33
- return p = h = void 0, $ = a, z = t.apply(T, v), z;
30
+ o = G(o) || 0, W(l) && (K = !!l.leading, C = "maxWait" in l, j = C ? D(G(l.maxWait) || 0, o) : j, A = "trailing" in l ? !!l.trailing : A);
31
+ function B(r) {
32
+ var b = p, S = x;
33
+ return p = x = void 0, T = r, z = t.apply(S, b), z;
34
34
  }
35
- function oe(a) {
36
- return $ = a, u = setTimeout(S, i), K ? B(a) : z;
35
+ function oe(r) {
36
+ return T = r, u = setTimeout(O, o), K ? B(r) : z;
37
37
  }
38
- function ne(a) {
39
- var v = a - y, T = a - $, Q = i - v;
40
- return _ ? q(Q, W - T) : Q;
38
+ function ne(r) {
39
+ var b = r - y, S = r - T, Q = o - b;
40
+ return C ? $(Q, j - S) : Q;
41
41
  }
42
- function X(a) {
43
- var v = a - y, T = a - $;
44
- return y === void 0 || v >= i || v < 0 || _ && T >= W;
42
+ function X(r) {
43
+ var b = r - y, S = r - T;
44
+ return y === void 0 || b >= o || b < 0 || C && S >= j;
45
45
  }
46
- function S() {
47
- var a = D();
48
- if (X(a))
49
- return J(a);
50
- u = setTimeout(S, ne(a));
46
+ function O() {
47
+ var r = _();
48
+ if (X(r))
49
+ return J(r);
50
+ u = setTimeout(O, ne(r));
51
51
  }
52
- function J(a) {
53
- return u = void 0, A && p ? B(a) : (p = h = void 0, z);
52
+ function J(r) {
53
+ return u = void 0, A && p ? B(r) : (p = x = void 0, z);
54
54
  }
55
55
  function se() {
56
- u !== void 0 && clearTimeout(u), $ = 0, p = y = h = u = void 0;
56
+ u !== void 0 && clearTimeout(u), T = 0, p = y = x = u = void 0;
57
57
  }
58
58
  function le() {
59
- return u === void 0 ? z : J(D());
59
+ return u === void 0 ? z : J(_());
60
60
  }
61
61
  function N() {
62
- var a = D(), v = X(a);
63
- if (p = arguments, h = this, y = a, v) {
62
+ var r = _(), b = X(r);
63
+ if (p = arguments, x = this, y = r, b) {
64
64
  if (u === void 0)
65
65
  return oe(y);
66
- if (_)
67
- return u = setTimeout(S, i), B(y);
66
+ if (C)
67
+ return u = setTimeout(O, o), B(y);
68
68
  }
69
- return u === void 0 && (u = setTimeout(S, i)), z;
69
+ return u === void 0 && (u = setTimeout(O, o)), z;
70
70
  }
71
71
  return N.cancel = se, N.flush = le, N;
72
72
  }
73
- function re(t, i, n) {
74
- var p = !0, h = !0;
73
+ function ae(t, o, l) {
74
+ var p = !0, x = !0;
75
75
  if (typeof t != "function")
76
76
  throw new TypeError(e);
77
- return w(n) && (p = "leading" in n ? !!n.leading : p, h = "trailing" in n ? !!n.trailing : h), te(t, i, {
77
+ return W(l) && (p = "leading" in l ? !!l.leading : p, x = "trailing" in l ? !!l.trailing : x), te(t, o, {
78
78
  leading: p,
79
- maxWait: i,
80
- trailing: h
79
+ maxWait: o,
80
+ trailing: x
81
81
  });
82
82
  }
83
- function w(t) {
84
- var i = typeof t;
85
- return !!t && (i == "object" || i == "function");
83
+ function W(t) {
84
+ var o = typeof t;
85
+ return !!t && (o == "object" || o == "function");
86
86
  }
87
- function ae(t) {
87
+ function re(t) {
88
88
  return !!t && typeof t == "object";
89
89
  }
90
90
  function ie(t) {
91
- return typeof t == "symbol" || ae(t) && L.call(t) == b;
91
+ return typeof t == "symbol" || re(t) && q.call(t) == h;
92
92
  }
93
93
  function G(t) {
94
94
  if (typeof t == "number")
95
95
  return t;
96
96
  if (ie(t))
97
- return l;
98
- if (w(t)) {
99
- var i = typeof t.valueOf == "function" ? t.valueOf() : t;
100
- t = w(i) ? i + "" : i;
97
+ return n;
98
+ if (W(t)) {
99
+ var o = typeof t.valueOf == "function" ? t.valueOf() : t;
100
+ t = W(o) ? o + "" : o;
101
101
  }
102
102
  if (typeof t != "string")
103
103
  return t === 0 ? t : +t;
104
- t = t.replace(x, "");
105
- var n = m.test(t);
106
- return n || f.test(t) ? E(t.slice(2), n ? 2 : 8) : c.test(t) ? l : +t;
104
+ t = t.replace(v, "");
105
+ var l = m.test(t);
106
+ return l || g.test(t) ? F(t.slice(2), l ? 2 : 8) : c.test(t) ? n : +t;
107
107
  }
108
- return V = re, V;
108
+ return V = ae, V;
109
109
  }
110
110
  var ye = me();
111
111
  const ze = /* @__PURE__ */ be(ye), ke = "*,*:after,*:before{box-sizing:inherit}:host{display:block}.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-border-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.is-readonly{--textarea-background-color: var(--dt-color-container-subtle);--textarea-border-color: var(--dt-color-border-form)}.c-textareaWrapper.is-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(.is-disabled,.is-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))))}@supports (background-color: color-mix(in srgb,black,white)){.c-textareaWrapper:hover:not(.is-disabled,.is-readonly){--textarea-background-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-container-default))}}}.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-height: auto;--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--resize-none{--textarea-height: auto}.c-textareaWrapper.has-error{--textarea-border-color: var(--dt-color-support-error)}", $e = ["small", "medium", "large"], _e = ["auto", "manual", "none"], Te = ["default", "success", "error"], d = {
@@ -119,21 +119,21 @@ const ze = /* @__PURE__ */ be(ye), ke = "*,*:after,*:before{box-sizing:inherit}:
119
119
  readonly: !1,
120
120
  required: !1
121
121
  };
122
- var Ce = Object.defineProperty, we = Object.getOwnPropertyDescriptor, o = (e, l, b, x) => {
123
- for (var c = x > 1 ? void 0 : x ? we(l, b) : l, m = e.length - 1, f; m >= 0; m--)
124
- (f = e[m]) && (c = (x ? f(l, b, c) : f(c)) || c);
125
- return x && c && Ce(l, b, c), c;
122
+ var Ce = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, i = (e, n, h, v) => {
123
+ for (var c = v > 1 ? void 0 : v ? Se(n, h) : n, m = e.length - 1, g; m >= 0; m--)
124
+ (g = e[m]) && (c = (v ? g(n, h, c) : g(c)) || c);
125
+ return v && c && Ce(n, h, c), c;
126
126
  };
127
- const C = "pie-textarea", H = "assistive-text";
128
- let r = class extends he(xe(fe(P))) {
127
+ const w = "pie-textarea", H = "assistive-text";
128
+ let a = class extends he(xe(fe(P))) {
129
129
  constructor() {
130
130
  super(...arguments), this.value = d.value, this.disabled = d.disabled, this.size = d.size, this.resize = d.resize, this.readonly = d.readonly, this.autoFocus = d.autoFocus, this.required = d.required, this.status = d.status, this._throttledResize = ze(() => {
131
131
  this.resize === "auto" && (this._textarea.style.height = "auto", this._textarea.style.height = `${this._textarea.scrollHeight}px`);
132
- }, 100), this.handleInput = (e, l) => {
133
- e ? this.value = e.target.value : l && (this.value = l), this._internals.setFormValue(this.value), this.handleResize();
132
+ }, 100), this.handleInput = (e, n) => {
133
+ e ? this.value = e.target.value : n && (this.value = n), this._internals.setFormValue(this.value), this.handleResize();
134
134
  }, this.handleChange = (e) => {
135
- const l = ve(e);
136
- this.dispatchEvent(l);
135
+ const n = ve(e);
136
+ this.dispatchEvent(n);
137
137
  }, this.handleKeyDown = (e) => {
138
138
  e.key === "Enter" && e.stopPropagation();
139
139
  };
@@ -169,6 +169,12 @@ let r = class extends he(xe(fe(P))) {
169
169
  formDisabledCallback(e) {
170
170
  this.disabled = e;
171
171
  }
172
+ /**
173
+ * Sets the selected text range on the underlying native textarea.
174
+ */
175
+ setSelectionRange(e, n, h = "none") {
176
+ this._textarea.setSelectionRange(e, n, h);
177
+ }
172
178
  /**
173
179
  * Called when the form that owns this component is reset.
174
180
  * Resets the value to the default value.
@@ -183,7 +189,7 @@ let r = class extends he(xe(fe(P))) {
183
189
  return Y`
184
190
  <pie-assistive-text
185
191
  id="${H}"
186
- variant=${g(this.status)}
192
+ variant=${f(this.status)}
187
193
  message=${this.assistiveText || ""}
188
194
  ?isVisuallyHidden=${!this.assistiveText}
189
195
  data-test-id="pie-textarea-assistive-text">
@@ -193,115 +199,120 @@ let r = class extends he(xe(fe(P))) {
193
199
  render() {
194
200
  const {
195
201
  disabled: e,
196
- resize: l,
197
- size: b,
198
- autocomplete: x,
202
+ resize: n,
203
+ size: h,
204
+ autocomplete: v,
199
205
  autoFocus: c,
200
206
  name: m,
201
- readonly: f,
202
- placeholder: E,
203
- value: I,
204
- required: F,
207
+ readonly: g,
208
+ placeholder: F,
209
+ value: R,
210
+ required: L,
205
211
  status: k,
206
- assistiveText: R,
207
- maxlength: L,
208
- rows: M
209
- } = this, q = {
212
+ assistiveText: M,
213
+ maxlength: q,
214
+ rows: D,
215
+ aria: $
216
+ } = this, _ = {
210
217
  "c-textareaWrapper": !0,
211
218
  "is-disabled": e,
212
- "is-readonly": f,
219
+ "is-readonly": g,
213
220
  "has-error": k === "error",
214
- [`c-textarea--resize-${l}`]: !0,
215
- [`c-textarea--${b}`]: !0
221
+ [`c-textarea--resize-${n}`]: !0,
222
+ [`c-textarea--${h}`]: !0
216
223
  };
217
224
  return Y`<div>
218
225
  <div
219
- class="${ue(q)}"
226
+ class="${ue(_)}"
220
227
  data-test-id="pie-textarea-wrapper">
221
228
  <textarea
222
- id="${C}"
223
- data-test-id="${C}"
224
- name=${g(m)}
225
- autocomplete=${g(x)}
226
- placeholder=${g(E)}
227
- .value=${pe(I)}
229
+ id="${w}"
230
+ data-test-id="${w}"
231
+ name=${f(m)}
232
+ autocomplete=${f(v)}
233
+ placeholder=${f(F)}
234
+ .value=${pe(R)}
228
235
  ?autofocus=${c}
229
- ?readonly=${f}
230
- ?required=${F}
236
+ ?readonly=${g}
237
+ ?required=${L}
231
238
  ?disabled=${e}
232
- aria-describedby=${g(R ? H : void 0)}
239
+ aria-label=${f($ == null ? void 0 : $.label)}
240
+ aria-describedby=${f(M ? H : void 0)}
233
241
  aria-invalid=${k === "error" ? "true" : "false"}
234
- aria-errormessage="${g(k === "error" ? H : void 0)}"
242
+ aria-errormessage="${f(k === "error" ? H : void 0)}"
235
243
  @input=${this.handleInput}
236
244
  @change=${this.handleChange}
237
- maxlength=${g(L)}
238
- rows=${g(M)}
245
+ maxlength=${f(q)}
246
+ rows=${f(D)}
239
247
  ></textarea>
240
248
  </div>
241
249
  ${this.renderAssistiveText()}
242
250
  </div>`;
243
251
  }
244
252
  };
245
- r.styles = ce(ke);
246
- o([
253
+ a.styles = ce(ke);
254
+ i([
247
255
  s({ type: String })
248
- ], r.prototype, "value", 2);
249
- o([
256
+ ], a.prototype, "value", 2);
257
+ i([
250
258
  s({ type: String })
251
- ], r.prototype, "defaultValue", 2);
252
- o([
259
+ ], a.prototype, "defaultValue", 2);
260
+ i([
253
261
  s({ type: Boolean, reflect: !0 })
254
- ], r.prototype, "disabled", 2);
255
- o([
262
+ ], a.prototype, "disabled", 2);
263
+ i([
256
264
  s({ type: String }),
257
- U(C, $e, d.size)
258
- ], r.prototype, "size", 2);
259
- o([
265
+ U(w, $e, d.size)
266
+ ], a.prototype, "size", 2);
267
+ i([
260
268
  s({ type: String }),
261
- U(C, _e, d.resize)
262
- ], r.prototype, "resize", 2);
263
- o([
269
+ U(w, _e, d.resize)
270
+ ], a.prototype, "resize", 2);
271
+ i([
264
272
  s({ type: Boolean })
265
- ], r.prototype, "readonly", 2);
266
- o([
273
+ ], a.prototype, "readonly", 2);
274
+ i([
267
275
  s({ type: Boolean })
268
- ], r.prototype, "autoFocus", 2);
269
- o([
276
+ ], a.prototype, "autoFocus", 2);
277
+ i([
270
278
  s({ type: Boolean })
271
- ], r.prototype, "required", 2);
272
- o([
279
+ ], a.prototype, "required", 2);
280
+ i([
273
281
  s({ type: String }),
274
- U(C, Te, d.status)
275
- ], r.prototype, "status", 2);
276
- o([
282
+ U(w, Te, d.status)
283
+ ], a.prototype, "status", 2);
284
+ i([
277
285
  s({ type: String })
278
- ], r.prototype, "assistiveText", 2);
279
- o([
286
+ ], a.prototype, "assistiveText", 2);
287
+ i([
280
288
  s({ type: String, reflect: !0 })
281
- ], r.prototype, "name", 2);
282
- o([
289
+ ], a.prototype, "name", 2);
290
+ i([
283
291
  s({ type: String })
284
- ], r.prototype, "autocomplete", 2);
285
- o([
292
+ ], a.prototype, "autocomplete", 2);
293
+ i([
286
294
  s({ type: String })
287
- ], r.prototype, "placeholder", 2);
288
- o([
295
+ ], a.prototype, "placeholder", 2);
296
+ i([
289
297
  s({ type: Number })
290
- ], r.prototype, "maxlength", 2);
291
- o([
298
+ ], a.prototype, "maxlength", 2);
299
+ i([
292
300
  s({ type: Number })
293
- ], r.prototype, "rows", 2);
294
- o([
301
+ ], a.prototype, "rows", 2);
302
+ i([
303
+ s({ type: Object })
304
+ ], a.prototype, "aria", 2);
305
+ i([
295
306
  ee("textarea")
296
- ], r.prototype, "_textarea", 2);
297
- o([
307
+ ], a.prototype, "_textarea", 2);
308
+ i([
298
309
  ee("textarea")
299
- ], r.prototype, "focusTarget", 2);
300
- r = o([
310
+ ], a.prototype, "focusTarget", 2);
311
+ a = i([
301
312
  ge("pie-textarea")
302
- ], r);
313
+ ], a);
303
314
  export {
304
- r as PieTextarea,
315
+ a as PieTextarea,
305
316
  d as defaultProps,
306
317
  _e as resizeModes,
307
318
  $e as sizes,
package/dist/react.d.ts CHANGED
@@ -9,10 +9,17 @@ import * as React_2 from 'react';
9
9
  import { RTLInterface } from '@justeattakeaway/pie-webc-core';
10
10
  import { TemplateResult } from 'lit-html';
11
11
 
12
+ declare type AriaProps = {
13
+ /**
14
+ * Provides an accessible label for the textarea. Should be used when no visible label is associated with the textarea.
15
+ */
16
+ label?: string;
17
+ };
18
+
12
19
  /**
13
20
  * The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
14
21
  */
15
- declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows'>>;
22
+ declare type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows' | 'aria'>>;
16
23
 
17
24
  /**
18
25
  * Default values for optional properties that have default fallback values in the component.
@@ -42,6 +49,7 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
42
49
  placeholder: TextareaProps['placeholder'];
43
50
  maxlength: TextareaProps['maxlength'];
44
51
  rows: TextareaProps['rows'];
52
+ aria: TextareaProps['aria'];
45
53
  private _textarea;
46
54
  focusTarget: HTMLElement;
47
55
  private _abortController;
@@ -62,6 +70,10 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
62
70
  * @param disabled - The latest disabled state of the input.
63
71
  */
64
72
  formDisabledCallback(disabled: boolean): void;
73
+ /**
74
+ * Sets the selected text range on the underlying native textarea.
75
+ */
76
+ setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: 'forward' | 'backward' | 'none'): void;
65
77
  /**
66
78
  * Called when the form that owns this component is reset.
67
79
  * Resets the value to the default value.
@@ -101,6 +113,10 @@ export declare const sizes: readonly ["small", "medium", "large"];
101
113
  export declare const statusTypes: readonly ["default", "success", "error"];
102
114
 
103
115
  export declare interface TextareaProps {
116
+ /**
117
+ * ARIA attributes for the textarea.
118
+ */
119
+ aria?: AriaProps;
104
120
  /**
105
121
  * Same as the HTML disabled attribute - indicates whether the textarea is disabled.
106
122
  */
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.21.2",
4
+ "version": "0.23.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/justeattakeaway/pie",
@@ -44,12 +44,12 @@
44
44
  "license": "Apache-2.0",
45
45
  "devDependencies": {
46
46
  "@justeattakeaway/pie-components-config": "0.21.3",
47
- "@justeattakeaway/pie-css": "1.3.0",
48
- "@justeattakeaway/pie-monorepo-utils": "0.9.6",
47
+ "@justeattakeaway/pie-css": "1.3.1",
48
+ "@justeattakeaway/pie-monorepo-utils": "0.9.7",
49
49
  "@types/lodash.throttle": "4.1.9"
50
50
  },
51
51
  "dependencies": {
52
- "@justeattakeaway/pie-assistive-text": "1.0.4",
52
+ "@justeattakeaway/pie-assistive-text": "1.0.5",
53
53
  "@justeattakeaway/pie-webc-core": "16.0.0",
54
54
  "lodash.throttle": "4.1.1"
55
55
  },
package/src/defs.ts CHANGED
@@ -4,7 +4,19 @@ export const sizes = ['small', 'medium', 'large'] as const;
4
4
  export const resizeModes = ['auto', 'manual', 'none'] as const;
5
5
  export const statusTypes = ['default', 'success', 'error'] as const;
6
6
 
7
+ type AriaProps = {
8
+ /**
9
+ * Provides an accessible label for the textarea. Should be used when no visible label is associated with the textarea.
10
+ */
11
+ label?: string;
12
+ }
13
+
7
14
  export interface TextareaProps {
15
+ /**
16
+ * ARIA attributes for the textarea.
17
+ */
18
+ aria?: AriaProps;
19
+
8
20
  /**
9
21
  * Same as the HTML disabled attribute - indicates whether the textarea is disabled.
10
22
  */
@@ -93,7 +105,7 @@ export interface TextareaProps {
93
105
  /**
94
106
  * The default values for the `TextareaProps` that are required (i.e. they have a fallback value in the component).
95
107
  */
96
- type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows'>>;
108
+ type DefaultProps = ComponentDefaultProps<TextareaProps, keyof Omit<TextareaProps, 'name' | 'autocomplete' | 'assistiveText' | 'defaultValue' | 'maxlength' | 'rows' | 'aria'>>;
97
109
 
98
110
  /**
99
111
  * Default values for optional properties that have default fallback values in the component.
package/src/index.ts CHANGED
@@ -81,6 +81,9 @@ export class PieTextarea extends FormControlMixin(RtlMixin(DelegatesFocusMixin(P
81
81
  @property({ type: Number })
82
82
  public rows: TextareaProps['rows'];
83
83
 
84
+ @property({ type: Object })
85
+ public aria: TextareaProps['aria'];
86
+
84
87
  @query('textarea')
85
88
  private _textarea!: HTMLTextAreaElement;
86
89
 
@@ -146,6 +149,17 @@ export class PieTextarea extends FormControlMixin(RtlMixin(DelegatesFocusMixin(P
146
149
  this.disabled = disabled;
147
150
  }
148
151
 
152
+ /**
153
+ * Sets the selected text range on the underlying native textarea.
154
+ */
155
+ public setSelectionRange (
156
+ selectionStart: number,
157
+ selectionEnd: number,
158
+ selectionDirection: 'forward' | 'backward' | 'none' = 'none',
159
+ ): void {
160
+ this._textarea.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
161
+ }
162
+
149
163
  /**
150
164
  * Called when the form that owns this component is reset.
151
165
  * Resets the value to the default value.
@@ -225,6 +239,7 @@ export class PieTextarea extends FormControlMixin(RtlMixin(DelegatesFocusMixin(P
225
239
  assistiveText,
226
240
  maxlength,
227
241
  rows,
242
+ aria,
228
243
  } = this;
229
244
 
230
245
  const classes = {
@@ -251,6 +266,7 @@ export class PieTextarea extends FormControlMixin(RtlMixin(DelegatesFocusMixin(P
251
266
  ?readonly=${readonly}
252
267
  ?required=${required}
253
268
  ?disabled=${disabled}
269
+ aria-label=${ifDefined(aria?.label)}
254
270
  aria-describedby=${ifDefined(assistiveText ? assistiveTextIdValue : undefined)}
255
271
  aria-invalid=${status === 'error' ? 'true' : 'false'}
256
272
  aria-errormessage="${ifDefined(status === 'error' ? assistiveTextIdValue : undefined)}"