@justeattakeaway/pie-switch 0.26.0 → 0.27.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.
@@ -146,6 +146,14 @@
146
146
  "attribute": "disabled",
147
147
  "reflects": true
148
148
  },
149
+ {
150
+ "kind": "field",
151
+ "name": "focusTarget",
152
+ "type": {
153
+ "text": "HTMLElement"
154
+ },
155
+ "privacy": "public"
156
+ },
149
157
  {
150
158
  "kind": "method",
151
159
  "name": "handleFormAssociation",
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { CSSResult } from 'lit';
2
2
  import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
3
3
  import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
4
4
  import type { LitElement } from 'lit';
5
+ import type { PIEInputElement } from '@justeattakeaway/pie-webc-core';
5
6
  import type { PropertyValues } from 'lit';
6
7
  import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
7
8
  import type { TemplateResult } from 'lit';
@@ -26,7 +27,7 @@ export declare const ON_SWITCH_CHANGED_EVENT = "change";
26
27
  * @tagname pie-switch
27
28
  * @event {CustomEvent} change - when the switch checked state is changed.
28
29
  */
29
- export declare class PieSwitch extends PieSwitch_base implements SwitchProps {
30
+ export declare class PieSwitch extends PieSwitch_base implements SwitchProps, PIEInputElement {
30
31
  private input?;
31
32
  protected firstUpdated(_changedProperties: PropertyValues<this>): void;
32
33
  protected updated(_changedProperties: PropertyValues<this>): void;
@@ -38,6 +39,7 @@ export declare class PieSwitch extends PieSwitch_base implements SwitchProps {
38
39
  value: string;
39
40
  name?: string;
40
41
  disabled: boolean;
42
+ focusTarget: HTMLElement;
41
43
  static styles: CSSResult;
42
44
  /**
43
45
  * Ensures that the form value and validation state are in sync with the component.
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { LitElement as Ct, html as A, nothing as x, unsafeCSS as xt } from "lit";
2
- import { query as Ft, property as E } from "lit/decorators.js";
3
- import { FormControlMixin as At, RtlMixin as It, wrapNativeEvent as St, validPropertyValues as Vt, defineCustomElement as Tt } from "@justeattakeaway/pie-webc-core";
1
+ import { LitElement as xt, html as A, nothing as x, unsafeCSS as Ft } from "lit";
2
+ import { query as nt, property as E } from "lit/decorators.js";
3
+ import { FormControlMixin as At, RtlMixin as It, wrapNativeEvent as St, validPropertyValues as Tt, defineCustomElement as Vt } from "@justeattakeaway/pie-webc-core";
4
4
  import "@justeattakeaway/pie-icons-webc/IconCheck";
5
5
  const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wrapper{display:inline-flex;align-items:center;gap:var(--dt-spacing-b);font-family:var(--dt-font-body-l-family);cursor:pointer}.c-switch-wrapper[disabled]{cursor:not-allowed}.c-switch{--switch-bg-color: var(--dt-color-interactive-form);--switch-bg-color--checked: var(--dt-color-interactive-brand);--switch-bg-color--disabled: var(--dt-color-disabled-01);--switch-width: 48px;--switch-height: 24px;--switch-control-size: 20px;--switch-padding: 2px;--switch-radius: var(--dt-radius-rounded-e);--switch-translation: calc(var(--switch-width) - var(--switch-control-size) - 2 * var(--switch-padding));position:relative;display:flex;width:var(--switch-width);height:var(--switch-height);flex-shrink:0;padding:var(--switch-padding);border-radius:var(--switch-radius);background-color:var(--switch-bg-color)}@media (prefers-reduced-motion: no-preference){.c-switch{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch:hover{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-hover-01)))}.c-switch:focus,.c-switch: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-switch:active{background-color:hsl(var(--dt-color-interactive-form-h),var(--dt-color-interactive-form-s),calc(var(--dt-color-interactive-form-l) - var(--dt-color-active-01)))}.c-switch[checked]{background-color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch[checked]{transition:background-color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch[checked]:hover{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.c-switch[checked]:focus,.c-switch[checked]:focus-within{background-color:var(--switch-bg-color--checked)}.c-switch[checked]:active{background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}[disabled] .c-switch{background-color:var(--switch-bg-color--disabled);pointer-events:none}.c-switch-input{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);border:0;left:50%;transform:translate(-50%) translateY(-50%);bottom:0}.c-switch-input:disabled{background-color:transparent}.c-switch-control{position:absolute;left:2px;width:var(--switch-control-size);height:var(--switch-control-size);border-radius:var(--switch-radius);background-color:var(--dt-color-interactive-light);padding:var(--switch-padding)}@media (prefers-reduced-motion: no-preference){.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control{transform:translate(var(--switch-translation))}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:checked+.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--checked)}@media (prefers-reduced-motion: no-preference){.c-switch-input:checked+.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-input:disabled~.c-switch-control{color:var(--switch-bg-color--disabled)}.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{color:var(--switch-bg-color--disabled)}@media (prefers-reduced-motion: no-preference){.c-switch-input:disabled~.c-switch-control .c-pieIcon--check{transition:color .15s cubic-bezier(.4,0,.9,1) 0s}}.c-switch-description{position:absolute;display:block;height:1px;width:1px;overflow:hidden;padding:1px;white-space:nowrap}.c-switch-wrapper[isRTL] .c-switch-control{position:absolute;left:initial;right:2px}.c-switch-wrapper[isRTL] .c-switch-input:checked+.c-switch-control{transform:translate(calc(-1 * var(--switch-translation)))}@media (prefers-reduced-motion: no-preference){.c-switch-wrapper[isRTL] .c-switch-input:checked+.c-switch-control{transition:transform .15s cubic-bezier(.4,0,.9,1) 0s}}
6
6
  `, Nt = ["leading", "trailing"], Wt = "change";
7
7
  (function() {
8
8
  (function(v) {
9
- const n = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), V = {
9
+ const n = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), T = {
10
10
  ariaAtomic: "aria-atomic",
11
11
  ariaAutoComplete: "aria-autocomplete",
12
12
  ariaBusy: "aria-busy",
@@ -48,11 +48,11 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
48
48
  ariaValueNow: "aria-valuenow",
49
49
  ariaValueText: "aria-valuetext",
50
50
  role: "role"
51
- }, ct = (e, t) => {
52
- for (let i in V) {
51
+ }, lt = (e, t) => {
52
+ for (let i in T) {
53
53
  t[i] = null;
54
54
  let a = null;
55
- const r = V[i];
55
+ const r = T[i];
56
56
  Object.defineProperty(t, i, {
57
57
  get() {
58
58
  return a;
@@ -93,8 +93,8 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
93
93
  var u;
94
94
  if (l.has(s) && s.constructor.formAssociated && K(s), I.has(s)) {
95
95
  const d = I.get(s);
96
- Object.keys(V).filter((f) => d[f] !== null).forEach((f) => {
97
- s.setAttribute(V[f], d[f]);
96
+ Object.keys(T).filter((f) => d[f] !== null).forEach((f) => {
97
+ s.setAttribute(T[f], d[f]);
98
98
  }), I.delete(s);
99
99
  }
100
100
  if (S.has(s)) {
@@ -102,14 +102,14 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
102
102
  s.setAttribute("internals-valid", d.validity.valid.toString()), s.setAttribute("internals-invalid", (!d.validity.valid).toString()), s.setAttribute("aria-invalid", (!d.validity.valid).toString()), S.delete(s);
103
103
  }
104
104
  if (s.localName === "form") {
105
- const d = y.get(s), b = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
105
+ const d = y.get(s), g = document.createTreeWalker(s, NodeFilter.SHOW_ELEMENT, {
106
106
  acceptNode(D) {
107
107
  return l.has(D) && D.constructor.formAssociated && !(d && d.has(D)) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
108
108
  }
109
109
  });
110
- let f = b.nextNode();
110
+ let f = g.nextNode();
111
111
  for (; f; )
112
- K(f), f = b.nextNode();
112
+ K(f), f = g.nextNode();
113
113
  }
114
114
  s.localName === "fieldset" && ((u = C.observe) == null || u.call(C, s, G), j(s, !0));
115
115
  }), o.forEach((s) => {
@@ -118,7 +118,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
118
118
  });
119
119
  });
120
120
  }
121
- function lt(e) {
121
+ function dt(e) {
122
122
  e.forEach((t) => {
123
123
  const { removedNodes: i } = t;
124
124
  i.forEach((a) => {
@@ -127,9 +127,9 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
127
127
  });
128
128
  });
129
129
  }
130
- const dt = (e) => {
130
+ const ht = (e) => {
131
131
  var i, a;
132
- const t = new MutationObserver(lt);
132
+ const t = new MutationObserver(dt);
133
133
  (i = window == null ? void 0 : window.ShadyDOM) != null && i.inUse && e.mode && e.host && (e = e.host), (a = t.observe) == null || a.call(t, e, { childList: !0 }), q.set(e, t);
134
134
  };
135
135
  N() && new MutationObserver(P);
@@ -145,7 +145,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
145
145
  }, J = (e, t) => {
146
146
  const i = document.createElement("input");
147
147
  return i.type = "hidden", i.name = e.getAttribute("name"), e.after(i), h.get(t).push(i), i;
148
- }, ht = (e, t) => {
148
+ }, ut = (e, t) => {
149
149
  var i;
150
150
  h.set(t, []), (i = C.observe) == null || i.call(C, e, G);
151
151
  }, Q = (e, t) => {
@@ -154,14 +154,14 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
154
154
  let i = t[0].id;
155
155
  t[0].id || (i = `${t[0].htmlFor}_Label`, t[0].id = i), e.setAttribute("aria-labelledby", i);
156
156
  }
157
- }, T = (e) => {
157
+ }, V = (e) => {
158
158
  const t = Array.from(e.elements).filter((o) => !o.tagName.includes("-") && o.validity).map((o) => o.validity.valid), i = y.get(e) || [], a = Array.from(i).filter((o) => o.isConnected).map((o) => l.get(o).validity.valid), r = [...t, ...a].includes(!1);
159
159
  e.toggleAttribute("internals-invalid", r), e.toggleAttribute("internals-valid", !r);
160
- }, ut = (e) => {
161
- T(L(e.target));
162
160
  }, pt = (e) => {
163
- T(L(e.target));
161
+ V(L(e.target));
164
162
  }, ft = (e) => {
163
+ V(L(e.target));
164
+ }, mt = (e) => {
165
165
  const t = ["button[type=submit]", "input[type=submit]", "button:not([type])"].map((i) => `${i}:not([disabled])`).map((i) => `${i}:not([form])${e.id ? `,${i}[form='${e.id}']` : ""}`).join(",");
166
166
  e.addEventListener("click", (i) => {
167
167
  if (i.target.closest(t)) {
@@ -171,7 +171,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
171
171
  r.size && Array.from(r).reverse().map((u) => l.get(u).reportValidity()).includes(!1) && i.preventDefault();
172
172
  }
173
173
  });
174
- }, mt = (e) => {
174
+ }, wt = (e) => {
175
175
  const t = y.get(e.target);
176
176
  t && t.size && t.forEach((i) => {
177
177
  i.constructor.formAssociated && i.formResetCallback && i.formResetCallback.apply(i);
@@ -183,16 +183,16 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
183
183
  a.add(e);
184
184
  else {
185
185
  const r = /* @__PURE__ */ new Set();
186
- r.add(e), y.set(t, r), ft(t), t.addEventListener("reset", mt), t.addEventListener("input", ut), t.addEventListener("change", pt);
186
+ r.add(e), y.set(t, r), mt(t), t.addEventListener("reset", wt), t.addEventListener("input", pt), t.addEventListener("change", ft);
187
187
  }
188
188
  k.set(t, { ref: e, internals: i }), e.constructor.formAssociated && e.formAssociatedCallback && setTimeout(() => {
189
189
  e.formAssociatedCallback.apply(e, [t]);
190
- }, 0), T(t);
190
+ }, 0), V(t);
191
191
  }
192
192
  }, L = (e) => {
193
193
  let t = e.parentNode;
194
194
  return t && t.tagName !== "FORM" && (t = L(t)), t;
195
- }, w = (e, t, i = DOMException) => {
195
+ }, b = (e, t, i = DOMException) => {
196
196
  if (!e.constructor.formAssociated)
197
197
  throw new i(t);
198
198
  }, Z = (e, t, i) => {
@@ -209,12 +209,12 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
209
209
  function N() {
210
210
  return typeof MutationObserver < "u";
211
211
  }
212
- class wt {
212
+ class bt {
213
213
  constructor() {
214
214
  this.badInput = !1, this.customError = !1, this.patternMismatch = !1, this.rangeOverflow = !1, this.rangeUnderflow = !1, this.stepMismatch = !1, this.tooLong = !1, this.tooShort = !1, this.typeMismatch = !1, this.valid = !0, this.valueMissing = !1, Object.seal(this);
215
215
  }
216
216
  }
217
- const bt = (e) => (e.badInput = !1, e.customError = !1, e.patternMismatch = !1, e.rangeOverflow = !1, e.rangeUnderflow = !1, e.stepMismatch = !1, e.tooLong = !1, e.tooShort = !1, e.typeMismatch = !1, e.valid = !0, e.valueMissing = !1, e), gt = (e, t, i) => (e.valid = vt(t), Object.keys(t).forEach((a) => e[a] = t[a]), i && T(i), e), vt = (e) => {
217
+ const gt = (e) => (e.badInput = !1, e.customError = !1, e.patternMismatch = !1, e.rangeOverflow = !1, e.rangeUnderflow = !1, e.stepMismatch = !1, e.tooLong = !1, e.tooShort = !1, e.typeMismatch = !1, e.valid = !0, e.valueMissing = !1, e), vt = (e, t, i) => (e.valid = yt(t), Object.keys(t).forEach((a) => e[a] = t[a]), i && V(i), e), yt = (e) => {
218
218
  let t = !0;
219
219
  for (let i in e)
220
220
  i !== "valid" && e[i] !== !1 && (t = !1);
@@ -259,7 +259,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
259
259
  throw new TypeError("Cannot read private member from an object whose class did not declare it");
260
260
  return i === "m" ? a : i === "a" ? a.call(e) : a ? a.value : t.get(e);
261
261
  }
262
- function yt(e, t, i, a, r) {
262
+ function Et(e, t, i, a, r) {
263
263
  if (a === "m")
264
264
  throw new TypeError("Private method is not writable");
265
265
  if (a === "a" && !r)
@@ -269,9 +269,9 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
269
269
  return a === "a" ? r.call(e, i) : r ? r.value = i : t.set(e, i), i;
270
270
  }
271
271
  var F;
272
- class Et {
272
+ class kt {
273
273
  constructor(t) {
274
- F.set(this, void 0), yt(this, F, t, "f");
274
+ F.set(this, void 0), Et(this, F, t, "f");
275
275
  for (let i = 0; i < t.length; i++) {
276
276
  let a = t[i];
277
277
  this[i] = a, a.hasAttribute("name") && (this[a.getAttribute("name")] = a);
@@ -291,7 +291,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
291
291
  return this[t] == null ? null : this[t];
292
292
  }
293
293
  }
294
- function kt() {
294
+ function Mt() {
295
295
  const e = HTMLFormElement.prototype.checkValidity;
296
296
  HTMLFormElement.prototype.checkValidity = i;
297
297
  const t = HTMLFormElement.prototype.reportValidity;
@@ -310,8 +310,8 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
310
310
  const s = r.call(this, ...o), u = Array.from(y.get(this) || []);
311
311
  if (u.length === 0)
312
312
  return s;
313
- const d = Array.from(s).concat(u).sort((b, f) => b.compareDocumentPosition ? b.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
314
- return new Et(d);
313
+ const d = Array.from(s).concat(u).sort((g, f) => g.compareDocumentPosition ? g.compareDocumentPosition(f) & 2 ? 1 : -1 : 0);
314
+ return new kt(d);
315
315
  }
316
316
  });
317
317
  }
@@ -322,12 +322,12 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
322
322
  constructor(t) {
323
323
  if (!t || !t.tagName || t.tagName.indexOf("-") === -1)
324
324
  throw new TypeError("Illegal constructor");
325
- const i = t.getRootNode(), a = new wt();
326
- this.states = new _(t), n.set(this, t), c.set(this, a), l.set(t, this), ct(t, this), ht(t, this), Object.seal(this), i instanceof DocumentFragment && dt(i);
325
+ const i = t.getRootNode(), a = new bt();
326
+ this.states = new _(t), n.set(this, t), c.set(this, a), l.set(t, this), lt(t, this), ut(t, this), Object.seal(this), i instanceof DocumentFragment && ht(i);
327
327
  }
328
328
  checkValidity() {
329
329
  const t = n.get(this);
330
- if (w(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
330
+ if (b(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
331
331
  return !0;
332
332
  const i = c.get(this);
333
333
  if (!i.valid) {
@@ -342,19 +342,19 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
342
342
  }
343
343
  get form() {
344
344
  const t = n.get(this);
345
- w(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
345
+ b(t, "Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");
346
346
  let i;
347
347
  return t.constructor.formAssociated === !0 && (i = L(t)), i;
348
348
  }
349
349
  get labels() {
350
350
  const t = n.get(this);
351
- w(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
351
+ b(t, "Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");
352
352
  const i = t.getAttribute("id"), a = t.getRootNode();
353
353
  return a && i ? a.querySelectorAll(`[for="${i}"]`) : [];
354
354
  }
355
355
  reportValidity() {
356
356
  const t = n.get(this);
357
- if (w(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
357
+ if (b(t, "Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
358
358
  return !0;
359
359
  const i = this.checkValidity(), a = B.get(this);
360
360
  if (a && !t.constructor.formAssociated)
@@ -363,7 +363,7 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
363
363
  }
364
364
  setFormValue(t) {
365
365
  const i = n.get(this);
366
- if (w(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Y(this), t != null && !(t instanceof FormData)) {
366
+ if (b(i, "Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."), Y(this), t != null && !(t instanceof FormData)) {
367
367
  if (i.getAttribute("name")) {
368
368
  const a = J(i, this);
369
369
  a.value = t;
@@ -379,19 +379,19 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
379
379
  }
380
380
  setValidity(t, i, a) {
381
381
  const r = n.get(this);
382
- if (w(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
382
+ if (b(r, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
383
383
  throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
384
384
  B.set(this, a);
385
385
  const o = c.get(this), s = {};
386
- for (const b in t)
387
- s[b] = t[b];
388
- Object.keys(s).length === 0 && bt(o);
386
+ for (const g in t)
387
+ s[g] = t[g];
388
+ Object.keys(s).length === 0 && gt(o);
389
389
  const u = { ...o, ...s };
390
390
  delete u.valid;
391
- const { valid: d } = gt(o, u, this.form);
391
+ const { valid: d } = vt(o, u, this.form);
392
392
  if (!d && !i)
393
393
  throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
394
- m.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : S.set(r, this);
394
+ w.set(this, d ? "" : i), r.isConnected ? (r.toggleAttribute("internals-invalid", !d), r.toggleAttribute("internals-valid", d), r.setAttribute("aria-invalid", `${!d}`)) : S.set(r, this);
395
395
  }
396
396
  get shadowRoot() {
397
397
  const t = n.get(this), i = z.get(t);
@@ -399,18 +399,18 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
399
399
  }
400
400
  get validationMessage() {
401
401
  const t = n.get(this);
402
- return w(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), m.get(this);
402
+ return b(t, "Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."), w.get(this);
403
403
  }
404
404
  get validity() {
405
405
  const t = n.get(this);
406
- return w(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), c.get(this);
406
+ return b(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), c.get(this);
407
407
  }
408
408
  get willValidate() {
409
409
  const t = n.get(this);
410
- return w(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
410
+ return b(t, "Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."), !(t.disabled || t.hasAttribute("disabled") || t.hasAttribute("readonly"));
411
411
  }
412
412
  }
413
- function Mt() {
413
+ function Ct() {
414
414
  if (typeof window > "u" || !window.ElementInternals || !HTMLElement.prototype.attachInternals)
415
415
  return !1;
416
416
  class e extends HTMLElement {
@@ -476,19 +476,19 @@ const Lt = `*,*:before,*:after{box-sizing:border-box;cursor:inherit}.c-switch-wr
476
476
  const i = Element.prototype.attachShadow;
477
477
  Element.prototype.attachShadow = t;
478
478
  }
479
- N() && typeof document < "u" && new MutationObserver(P).observe(document.documentElement, R), typeof HTMLFormElement < "u" && kt(), (e || typeof window < "u" && !window.CustomStateSet) && H();
479
+ N() && typeof document < "u" && new MutationObserver(P).observe(document.documentElement, R), typeof HTMLFormElement < "u" && Mt(), (e || typeof window < "u" && !window.CustomStateSet) && H();
480
480
  }
481
481
  }
482
- return !!customElements.polyfillWrapFlushCallback || (Mt() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : st(!1)), v.forceCustomStateSetPolyfill = H, v.forceElementInternalsPolyfill = st, Object.defineProperty(v, "__esModule", { value: !0 }), v;
482
+ return !!customElements.polyfillWrapFlushCallback || (Ct() ? typeof window < "u" && !window.CustomStateSet && H(HTMLElement.prototype.attachInternals) : st(!1)), v.forceCustomStateSetPolyfill = H, v.forceElementInternalsPolyfill = st, Object.defineProperty(v, "__esModule", { value: !0 }), v;
483
483
  })({});
484
484
  })();
485
- var Pt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, g = (v, n, c, h) => {
486
- for (var l = h > 1 ? void 0 : h ? Rt(n, c) : n, m = v.length - 1, k; m >= 0; m--)
487
- (k = v[m]) && (l = (h ? k(n, c, l) : k(l)) || l);
485
+ var Pt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, m = (v, n, c, h) => {
486
+ for (var l = h > 1 ? void 0 : h ? Rt(n, c) : n, w = v.length - 1, k; w >= 0; w--)
487
+ (k = v[w]) && (l = (h ? k(n, c, l) : k(l)) || l);
488
488
  return h && l && Pt(n, c, l), l;
489
489
  };
490
- const nt = "pie-switch";
491
- class p extends At(It(Ct)) {
490
+ const ct = "pie-switch";
491
+ class p extends At(It(xt)) {
492
492
  constructor() {
493
493
  super(...arguments), this.labelPlacement = "leading", this.checked = !1, this.required = !1, this.value = "on", this.disabled = !1;
494
494
  }
@@ -577,14 +577,14 @@ class p extends At(It(Ct)) {
577
577
  aria: c,
578
578
  checked: h,
579
579
  required: l,
580
- disabled: m,
580
+ disabled: w,
581
581
  isRTL: k
582
582
  } = this, M = "switch-description";
583
583
  return A`
584
584
  <div
585
585
  class="c-switch-wrapper"
586
586
  ?isRTL=${k}
587
- ?disabled=${m}>
587
+ ?disabled=${w}>
588
588
  ${n === "leading" ? this.renderSwitchLabel() : x}
589
589
  <label
590
590
  data-test-id="switch-component"
@@ -598,7 +598,7 @@ class p extends At(It(Ct)) {
598
598
  class="c-switch-input"
599
599
  .required=${l}
600
600
  .checked="${h}"
601
- .disabled="${m}"
601
+ .disabled="${w}"
602
602
  @change="${this.onChange}"
603
603
  aria-label="${(c == null ? void 0 : c.label) || x}"
604
604
  aria-describedby="${c != null && c.describedBy ? M : x}">
@@ -612,36 +612,39 @@ class p extends At(It(Ct)) {
612
612
  `;
613
613
  }
614
614
  }
615
- p.styles = xt(Lt);
616
- g([
617
- Ft('input[type="checkbox"]')
615
+ p.styles = Ft(Lt);
616
+ m([
617
+ nt('input[type="checkbox"]')
618
618
  ], p.prototype, "input", 2);
619
- g([
619
+ m([
620
620
  E({ type: String })
621
621
  ], p.prototype, "label", 2);
622
- g([
622
+ m([
623
623
  E({ type: String }),
624
- Vt(nt, Nt, "leading")
624
+ Tt(ct, Nt, "leading")
625
625
  ], p.prototype, "labelPlacement", 2);
626
- g([
626
+ m([
627
627
  E({ type: Object })
628
628
  ], p.prototype, "aria", 2);
629
- g([
629
+ m([
630
630
  E({ type: Boolean, reflect: !0 })
631
631
  ], p.prototype, "checked", 2);
632
- g([
632
+ m([
633
633
  E({ type: Boolean, reflect: !0 })
634
634
  ], p.prototype, "required", 2);
635
- g([
635
+ m([
636
636
  E({ type: String })
637
637
  ], p.prototype, "value", 2);
638
- g([
638
+ m([
639
639
  E({ type: String })
640
640
  ], p.prototype, "name", 2);
641
- g([
641
+ m([
642
642
  E({ type: Boolean, reflect: !0 })
643
643
  ], p.prototype, "disabled", 2);
644
- Tt(nt, p);
644
+ m([
645
+ nt("label")
646
+ ], p.prototype, "focusTarget", 2);
647
+ Vt(ct, p);
645
648
  export {
646
649
  Wt as ON_SWITCH_CHANGED_EVENT,
647
650
  p as PieSwitch,
package/dist/react.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { CSSResult } from 'lit';
2
2
  import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
3
3
  import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
4
4
  import type { LitElement } from 'lit';
5
+ import type { PIEInputElement } from '@justeattakeaway/pie-webc-core';
5
6
  import type { PropertyValues } from 'lit';
6
7
  import * as React_2 from 'react';
7
8
  import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
@@ -29,7 +30,7 @@ export declare const PieSwitch: React_2.ForwardRefExoticComponent<SwitchProps &
29
30
  * @tagname pie-switch
30
31
  * @event {CustomEvent} change - when the switch checked state is changed.
31
32
  */
32
- declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps {
33
+ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps, PIEInputElement {
33
34
  private input?;
34
35
  protected firstUpdated(_changedProperties: PropertyValues<this>): void;
35
36
  protected updated(_changedProperties: PropertyValues<this>): void;
@@ -41,6 +42,7 @@ declare class PieSwitch_2 extends PieSwitch_base implements SwitchProps {
41
42
  value: string;
42
43
  name?: string;
43
44
  disabled: boolean;
45
+ focusTarget: HTMLElement;
44
46
  static styles: CSSResult;
45
47
  /**
46
48
  * Ensures that the form value and validation state are in sync with the component.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-switch",
3
3
  "description": "PIE Design System Switch built using Web Components",
4
- "version": "0.26.0",
4
+ "version": "0.27.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -32,12 +32,12 @@
32
32
  "license": "Apache-2.0",
33
33
  "devDependencies": {
34
34
  "@custom-elements-manifest/analyzer": "0.9.0",
35
- "@justeattakeaway/pie-components-config": "0.9.0",
35
+ "@justeattakeaway/pie-components-config": "0.11.0",
36
36
  "cem-plugin-module-file-extensions": "0.0.5"
37
37
  },
38
38
  "dependencies": {
39
- "@justeattakeaway/pie-icons-webc": "0.17.2",
40
- "@justeattakeaway/pie-webc-core": "0.17.1",
39
+ "@justeattakeaway/pie-icons-webc": "0.17.3",
40
+ "@justeattakeaway/pie-webc-core": "0.18.0",
41
41
  "@justeattakeaway/pie-wrapper-react": "0.14.0",
42
42
  "element-internals-polyfill": "1.3.10"
43
43
  },
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  } from 'lit';
4
4
  import { property, query } from 'lit/decorators.js';
5
5
  import {
6
- RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin, wrapNativeEvent,
6
+ RtlMixin, validPropertyValues, defineCustomElement, FormControlMixin, wrapNativeEvent, PIEInputElement,
7
7
  } from '@justeattakeaway/pie-webc-core';
8
8
  import styles from './switch.scss?inline';
9
9
  import {
@@ -21,7 +21,7 @@ const componentSelector = 'pie-switch';
21
21
  * @tagname pie-switch
22
22
  * @event {CustomEvent} change - when the switch checked state is changed.
23
23
  */
24
- export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements SwitchProps {
24
+ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements SwitchProps, PIEInputElement {
25
25
  @query('input[type="checkbox"]')
26
26
  private input?: HTMLInputElement;
27
27
 
@@ -66,6 +66,9 @@ export class PieSwitch extends FormControlMixin(RtlMixin(LitElement)) implements
66
66
  @property({ type: Boolean, reflect: true })
67
67
  public disabled = false;
68
68
 
69
+ @query('label')
70
+ public focusTarget!: HTMLElement;
71
+
69
72
  static styles = unsafeCSS(styles);
70
73
 
71
74
  /**