@justeattakeaway/pie-textarea 0.21.2 → 0.22.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)
@@ -66,6 +67,11 @@ This component does not expose any CSS variables for style overrides.
66
67
  | `change` | Fires when the textarea loses focus after the value has been changed. |
67
68
  | `input` | Fires when the textarea value is changed. |
68
69
 
70
+ ### Methods
71
+ | Method | Parameters | Description | Returns |
72
+ |--------|------------|-------------|---------|
73
+ | `setSelectionRange` | `selectionStart: number`, `selectionEnd: number`, `selectionDirection?: "forward" | "backward" | "none"` | Sets the selected text range on the underlying native textarea element. | `void` |
74
+
69
75
  ## Forms Usage
70
76
  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
77
 
@@ -262,6 +262,38 @@
262
262
  ],
263
263
  "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
264
  },
265
+ {
266
+ "kind": "method",
267
+ "name": "setSelectionRange",
268
+ "privacy": "public",
269
+ "return": {
270
+ "type": {
271
+ "text": "void"
272
+ }
273
+ },
274
+ "parameters": [
275
+ {
276
+ "name": "selectionStart",
277
+ "type": {
278
+ "text": "number"
279
+ }
280
+ },
281
+ {
282
+ "name": "selectionEnd",
283
+ "type": {
284
+ "text": "number"
285
+ }
286
+ },
287
+ {
288
+ "name": "selectionDirection",
289
+ "default": "'none'",
290
+ "type": {
291
+ "text": "'forward' | 'backward' | 'none'"
292
+ }
293
+ }
294
+ ],
295
+ "description": "Sets the selected text range on the underlying native textarea."
296
+ },
265
297
  {
266
298
  "kind": "method",
267
299
  "name": "formResetCallback",
package/dist/index.d.ts CHANGED
@@ -59,6 +59,10 @@ export declare class PieTextarea extends PieTextarea_base implements TextareaPro
59
59
  * @param disabled - The latest disabled state of the input.
60
60
  */
61
61
  formDisabledCallback(disabled: boolean): void;
62
+ /**
63
+ * Sets the selected text range on the underlying native textarea.
64
+ */
65
+ setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: 'forward' | 'backward' | 'none'): void;
62
66
  /**
63
67
  * Called when the form that owns this component is reset.
64
68
  * Resets the value to the default value.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LitElement as de, html as Y, unsafeCSS as ce } from "lit";
2
- import { property as s, query as ee } from "lit/decorators.js";
2
+ import { property as l, 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 b } 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";
@@ -10,7 +10,7 @@ const O = class O extends de {
10
10
  this.getAttribute("v") || this.setAttribute("v", O.v);
11
11
  }
12
12
  };
13
- O.v = "0.21.2";
13
+ O.v = "0.22.0";
14
14
  let P = O;
15
15
  var j = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
16
16
  function be(e) {
@@ -20,67 +20,67 @@ 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]", f = /^\s+|\s+$/g, c = /^[-+]0x[0-9a-f]+$/i, m = /^0b[01]+$/i, v = /^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() {
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, i, s) {
27
+ var p, x, w, z, u, y, $ = 0, K = !1, _ = !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);
30
+ i = G(i) || 0, S(s) && (K = !!s.leading, _ = "maxWait" in s, w = _ ? M(G(s.maxWait) || 0, i) : w, A = "trailing" in s ? !!s.trailing : A);
31
31
  function B(a) {
32
- var v = p, T = h;
33
- return p = h = void 0, $ = a, z = t.apply(T, v), z;
32
+ var g = p, T = x;
33
+ return p = x = void 0, $ = a, z = t.apply(T, g), z;
34
34
  }
35
35
  function oe(a) {
36
- return $ = a, u = setTimeout(S, i), K ? B(a) : z;
36
+ return $ = a, u = setTimeout(W, i), K ? B(a) : z;
37
37
  }
38
38
  function ne(a) {
39
- var v = a - y, T = a - $, Q = i - v;
40
- return _ ? q(Q, W - T) : Q;
39
+ var g = a - y, T = a - $, Q = i - g;
40
+ return _ ? q(Q, w - T) : Q;
41
41
  }
42
42
  function X(a) {
43
- var v = a - y, T = a - $;
44
- return y === void 0 || v >= i || v < 0 || _ && T >= W;
43
+ var g = a - y, T = a - $;
44
+ return y === void 0 || g >= i || g < 0 || _ && T >= w;
45
45
  }
46
- function S() {
46
+ function W() {
47
47
  var a = D();
48
48
  if (X(a))
49
49
  return J(a);
50
- u = setTimeout(S, ne(a));
50
+ u = setTimeout(W, ne(a));
51
51
  }
52
52
  function J(a) {
53
- return u = void 0, A && p ? B(a) : (p = h = void 0, z);
53
+ return u = void 0, A && p ? B(a) : (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), $ = 0, p = y = x = u = void 0;
57
57
  }
58
58
  function le() {
59
59
  return u === void 0 ? z : J(D());
60
60
  }
61
61
  function N() {
62
- var a = D(), v = X(a);
63
- if (p = arguments, h = this, y = a, v) {
62
+ var a = D(), g = X(a);
63
+ if (p = arguments, x = this, y = a, g) {
64
64
  if (u === void 0)
65
65
  return oe(y);
66
66
  if (_)
67
- return u = setTimeout(S, i), B(y);
67
+ return u = setTimeout(W, i), B(y);
68
68
  }
69
- return u === void 0 && (u = setTimeout(S, i)), z;
69
+ return u === void 0 && (u = setTimeout(W, i)), 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 re(t, i, s) {
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 S(s) && (p = "leading" in s ? !!s.leading : p, x = "trailing" in s ? !!s.trailing : x), te(t, i, {
78
78
  leading: p,
79
79
  maxWait: i,
80
- trailing: h
80
+ trailing: x
81
81
  });
82
82
  }
83
- function w(t) {
83
+ function S(t) {
84
84
  var i = typeof t;
85
85
  return !!t && (i == "object" || i == "function");
86
86
  }
@@ -88,22 +88,22 @@ function me() {
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" || ae(t) && L.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)) {
97
+ return n;
98
+ if (S(t)) {
99
99
  var i = typeof t.valueOf == "function" ? t.valueOf() : t;
100
- t = w(i) ? i + "" : i;
100
+ t = S(i) ? i + "" : i;
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(f, "");
105
+ var s = m.test(t);
106
+ return s || v.test(t) ? E(t.slice(2), s ? 2 : 8) : c.test(t) ? n : +t;
107
107
  }
108
108
  return V = re, V;
109
109
  }
@@ -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, o = (e, n, h, f) => {
123
+ for (var c = f > 1 ? void 0 : f ? Se(n, h) : n, m = e.length - 1, v; m >= 0; m--)
124
+ (v = e[m]) && (c = (f ? v(n, h, c) : v(c)) || c);
125
+ return f && c && Ce(n, h, c), c;
126
126
  };
127
127
  const C = "pie-textarea", H = "assistive-text";
128
128
  let r = 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=${b(this.status)}
187
193
  message=${this.assistiveText || ""}
188
194
  ?isVisuallyHidden=${!this.assistiveText}
189
195
  data-test-id="pie-textarea-assistive-text">
@@ -193,12 +199,12 @@ 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: f,
199
205
  autoFocus: c,
200
206
  name: m,
201
- readonly: f,
207
+ readonly: v,
202
208
  placeholder: E,
203
209
  value: I,
204
210
  required: F,
@@ -209,10 +215,10 @@ let r = class extends he(xe(fe(P))) {
209
215
  } = this, q = {
210
216
  "c-textareaWrapper": !0,
211
217
  "is-disabled": e,
212
- "is-readonly": f,
218
+ "is-readonly": v,
213
219
  "has-error": k === "error",
214
- [`c-textarea--resize-${l}`]: !0,
215
- [`c-textarea--${b}`]: !0
220
+ [`c-textarea--resize-${n}`]: !0,
221
+ [`c-textarea--${h}`]: !0
216
222
  };
217
223
  return Y`<div>
218
224
  <div
@@ -221,21 +227,21 @@ let r = class extends he(xe(fe(P))) {
221
227
  <textarea
222
228
  id="${C}"
223
229
  data-test-id="${C}"
224
- name=${g(m)}
225
- autocomplete=${g(x)}
226
- placeholder=${g(E)}
230
+ name=${b(m)}
231
+ autocomplete=${b(f)}
232
+ placeholder=${b(E)}
227
233
  .value=${pe(I)}
228
234
  ?autofocus=${c}
229
- ?readonly=${f}
235
+ ?readonly=${v}
230
236
  ?required=${F}
231
237
  ?disabled=${e}
232
- aria-describedby=${g(R ? H : void 0)}
238
+ aria-describedby=${b(R ? H : void 0)}
233
239
  aria-invalid=${k === "error" ? "true" : "false"}
234
- aria-errormessage="${g(k === "error" ? H : void 0)}"
240
+ aria-errormessage="${b(k === "error" ? H : void 0)}"
235
241
  @input=${this.handleInput}
236
242
  @change=${this.handleChange}
237
- maxlength=${g(L)}
238
- rows=${g(M)}
243
+ maxlength=${b(L)}
244
+ rows=${b(M)}
239
245
  ></textarea>
240
246
  </div>
241
247
  ${this.renderAssistiveText()}
@@ -244,52 +250,52 @@ let r = class extends he(xe(fe(P))) {
244
250
  };
245
251
  r.styles = ce(ke);
246
252
  o([
247
- s({ type: String })
253
+ l({ type: String })
248
254
  ], r.prototype, "value", 2);
249
255
  o([
250
- s({ type: String })
256
+ l({ type: String })
251
257
  ], r.prototype, "defaultValue", 2);
252
258
  o([
253
- s({ type: Boolean, reflect: !0 })
259
+ l({ type: Boolean, reflect: !0 })
254
260
  ], r.prototype, "disabled", 2);
255
261
  o([
256
- s({ type: String }),
262
+ l({ type: String }),
257
263
  U(C, $e, d.size)
258
264
  ], r.prototype, "size", 2);
259
265
  o([
260
- s({ type: String }),
266
+ l({ type: String }),
261
267
  U(C, _e, d.resize)
262
268
  ], r.prototype, "resize", 2);
263
269
  o([
264
- s({ type: Boolean })
270
+ l({ type: Boolean })
265
271
  ], r.prototype, "readonly", 2);
266
272
  o([
267
- s({ type: Boolean })
273
+ l({ type: Boolean })
268
274
  ], r.prototype, "autoFocus", 2);
269
275
  o([
270
- s({ type: Boolean })
276
+ l({ type: Boolean })
271
277
  ], r.prototype, "required", 2);
272
278
  o([
273
- s({ type: String }),
279
+ l({ type: String }),
274
280
  U(C, Te, d.status)
275
281
  ], r.prototype, "status", 2);
276
282
  o([
277
- s({ type: String })
283
+ l({ type: String })
278
284
  ], r.prototype, "assistiveText", 2);
279
285
  o([
280
- s({ type: String, reflect: !0 })
286
+ l({ type: String, reflect: !0 })
281
287
  ], r.prototype, "name", 2);
282
288
  o([
283
- s({ type: String })
289
+ l({ type: String })
284
290
  ], r.prototype, "autocomplete", 2);
285
291
  o([
286
- s({ type: String })
292
+ l({ type: String })
287
293
  ], r.prototype, "placeholder", 2);
288
294
  o([
289
- s({ type: Number })
295
+ l({ type: Number })
290
296
  ], r.prototype, "maxlength", 2);
291
297
  o([
292
- s({ type: Number })
298
+ l({ type: Number })
293
299
  ], r.prototype, "rows", 2);
294
300
  o([
295
301
  ee("textarea")
package/dist/react.d.ts CHANGED
@@ -62,6 +62,10 @@ declare class PieTextarea_2 extends PieTextarea_base implements TextareaProps, P
62
62
  * @param disabled - The latest disabled state of the input.
63
63
  */
64
64
  formDisabledCallback(disabled: boolean): void;
65
+ /**
66
+ * Sets the selected text range on the underlying native textarea.
67
+ */
68
+ setSelectionRange(selectionStart: number, selectionEnd: number, selectionDirection?: 'forward' | 'backward' | 'none'): void;
65
69
  /**
66
70
  * Called when the form that owns this component is reset.
67
71
  * Resets the value to the default value.
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.22.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/justeattakeaway/pie",
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "@justeattakeaway/pie-components-config": "0.21.3",
47
47
  "@justeattakeaway/pie-css": "1.3.0",
48
- "@justeattakeaway/pie-monorepo-utils": "0.9.6",
48
+ "@justeattakeaway/pie-monorepo-utils": "0.9.7",
49
49
  "@types/lodash.throttle": "4.1.9"
50
50
  },
51
51
  "dependencies": {
package/src/index.ts CHANGED
@@ -146,6 +146,17 @@ export class PieTextarea extends FormControlMixin(RtlMixin(DelegatesFocusMixin(P
146
146
  this.disabled = disabled;
147
147
  }
148
148
 
149
+ /**
150
+ * Sets the selected text range on the underlying native textarea.
151
+ */
152
+ public setSelectionRange (
153
+ selectionStart: number,
154
+ selectionEnd: number,
155
+ selectionDirection: 'forward' | 'backward' | 'none' = 'none',
156
+ ): void {
157
+ this._textarea.setSelectionRange(selectionStart, selectionEnd, selectionDirection);
158
+ }
159
+
149
160
  /**
150
161
  * Called when the form that owns this component is reset.
151
162
  * Resets the value to the default value.