agnosticui-core 2.0.0-alpha.18 → 2.0.0-alpha.19
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.
|
@@ -113,9 +113,19 @@ export declare class AgRadio extends AgRadio_base implements RadioProps {
|
|
|
113
113
|
*/
|
|
114
114
|
private _syncFormValue;
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* Returns true if any ag-radio in this named group is checked.
|
|
117
|
+
* Uses the same DOM-traversal logic as uncheckOtherRadiosInGroup so it
|
|
118
|
+
* works whether the radios are in the document or nested inside a shadow root.
|
|
119
|
+
*/
|
|
120
|
+
private _isGroupChecked;
|
|
121
|
+
/**
|
|
122
|
+
* Sync validity to ElementInternals.
|
|
123
|
+
*
|
|
124
|
+
* Shadow DOM isolation prevents the inner <input type="radio"> from seeing
|
|
125
|
+
* sibling ag-radio elements in separate shadow trees, so native delegation
|
|
126
|
+
* would report each unchecked required radio as invalid individually.
|
|
127
|
+
* Instead we query the DOM directly: a required radio group is valid when
|
|
128
|
+
* ANY radio with the same name is checked.
|
|
119
129
|
*/
|
|
120
130
|
private _syncValidity;
|
|
121
131
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_Radio.d.ts","sourceRoot":"","sources":["../../../../src/components/Radio/core/_Radio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,KAAK,CAAC;AAUrD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AACrD,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;AAG1E,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,gBAAgB,GAAG,WAAW,CA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AAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAiBvB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAYrB;;;OAGG;IACM,iBAAiB,IAAI,IAAI;IAOlC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,WAAW;IASV,YAAY;IASZ,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAaxD,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,aAAa;IAgErB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,YAAY;IA0CpB,OAAO,CAAC,yBAAyB;IA2BjC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;IACH,OAAO,CAAC,YAAY;IAapB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IASlB,MAAM;CA+DhB"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { LitElement as p, css as b, nothing as c, html as h } from "lit";
|
|
2
|
-
import { n as
|
|
3
|
-
import { formControlStyles as
|
|
4
|
-
import { createFormControlIds as
|
|
5
|
-
import { FaceMixin as m
|
|
6
|
-
var
|
|
7
|
-
for (var
|
|
8
|
-
(l =
|
|
9
|
-
return
|
|
2
|
+
import { n as s } from "../../../property-CemaeiRl.js";
|
|
3
|
+
import { formControlStyles as f } from "../../../shared/form-control-styles.js";
|
|
4
|
+
import { createFormControlIds as v, buildAriaDescribedBy as w } from "../../../shared/form-control-utils.js";
|
|
5
|
+
import { FaceMixin as m } from "../../../shared/face-mixin.js";
|
|
6
|
+
var y = Object.defineProperty, d = (u, e, a, t) => {
|
|
7
|
+
for (var r = void 0, i = u.length - 1, l; i >= 0; i--)
|
|
8
|
+
(l = u[i]) && (r = l(e, a, r) || r);
|
|
9
|
+
return r && y(e, a, r), r;
|
|
10
10
|
}, n;
|
|
11
|
-
const
|
|
11
|
+
const o = (n = class extends m(p) {
|
|
12
12
|
constructor() {
|
|
13
|
-
super(...arguments), this.value = "", this.checked = !1, this.disabled = !1, this.size = "medium", this.theme = "primary", this.labelText = "", this.labelPosition = "end", this.label = "", this.labelHidden = !1, this.noLabel = !1, this.required = !1, this.invalid = !1, this.errorMessage = "", this.helpText = "", this._ids =
|
|
13
|
+
super(...arguments), this.value = "", this.checked = !1, this.disabled = !1, this.size = "medium", this.theme = "primary", this.labelText = "", this.labelPosition = "end", this.label = "", this.labelHidden = !1, this.noLabel = !1, this.required = !1, this.invalid = !1, this.errorMessage = "", this.helpText = "", this._ids = v("ag-radio");
|
|
14
14
|
}
|
|
15
15
|
// ─── FACE ─────────────────────────────────────────────────────────────────
|
|
16
16
|
/**
|
|
@@ -23,12 +23,40 @@ const t = (n = class extends m(p) {
|
|
|
23
23
|
this._internals.setFormValue(this.checked ? this.value : null);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* Returns true if any ag-radio in this named group is checked.
|
|
27
|
+
* Uses the same DOM-traversal logic as uncheckOtherRadiosInGroup so it
|
|
28
|
+
* works whether the radios are in the document or nested inside a shadow root.
|
|
29
|
+
*/
|
|
30
|
+
_isGroupChecked() {
|
|
31
|
+
if (this.checked) return !0;
|
|
32
|
+
let e = this.getRootNode();
|
|
33
|
+
for (; e && "host" in e; ) {
|
|
34
|
+
const t = e.host?.getRootNode();
|
|
35
|
+
if (t && t !== e)
|
|
36
|
+
e = t;
|
|
37
|
+
else
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const a = e instanceof Document ? e : document;
|
|
41
|
+
return Array.from(a.querySelectorAll(`ag-radio[name="${this.name}"]`)).some(
|
|
42
|
+
(t) => t.checked
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sync validity to ElementInternals.
|
|
47
|
+
*
|
|
48
|
+
* Shadow DOM isolation prevents the inner <input type="radio"> from seeing
|
|
49
|
+
* sibling ag-radio elements in separate shadow trees, so native delegation
|
|
50
|
+
* would report each unchecked required radio as invalid individually.
|
|
51
|
+
* Instead we query the DOM directly: a required radio group is valid when
|
|
52
|
+
* ANY radio with the same name is checked.
|
|
29
53
|
*/
|
|
30
54
|
_syncValidity() {
|
|
31
|
-
|
|
55
|
+
if (!this.required) {
|
|
56
|
+
this._internals.setValidity({});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._isGroupChecked() ? this._internals.setValidity({}) : this._internals.setValidity({ valueMissing: !0 }, "Please select one of these options.");
|
|
32
60
|
}
|
|
33
61
|
/**
|
|
34
62
|
* FACE lifecycle: called when the parent form is reset.
|
|
@@ -56,64 +84,64 @@ const t = (n = class extends m(p) {
|
|
|
56
84
|
firstUpdated() {
|
|
57
85
|
this.inputRef = this.shadowRoot?.querySelector(".radio-input"), this._syncFormValue(), this._syncValidity(), this._syncStates();
|
|
58
86
|
}
|
|
59
|
-
updated(
|
|
60
|
-
super.updated(
|
|
87
|
+
updated(e) {
|
|
88
|
+
super.updated(e), e.has("checked") && (this._syncFormValue(), this._syncValidity(), this._syncStates());
|
|
61
89
|
}
|
|
62
|
-
handleClick(
|
|
63
|
-
this.onClick && this.onClick(
|
|
90
|
+
handleClick(e) {
|
|
91
|
+
this.onClick && this.onClick(e);
|
|
64
92
|
}
|
|
65
|
-
handleKeyDown(
|
|
66
|
-
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"].includes(
|
|
93
|
+
handleKeyDown(e) {
|
|
94
|
+
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key))
|
|
67
95
|
return;
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
const l =
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
const a = this.getRadiosInGroup();
|
|
98
|
+
if (a.length === 0) return;
|
|
99
|
+
const t = a.indexOf(this);
|
|
100
|
+
if (t === -1) return;
|
|
101
|
+
let r;
|
|
102
|
+
e.key === "Home" ? r = 0 : e.key === "End" ? r = a.length - 1 : e.key === "ArrowDown" || e.key === "ArrowRight" ? r = (t + 1) % a.length : r = (t - 1 + a.length) % a.length;
|
|
103
|
+
const i = a[r];
|
|
104
|
+
if (i && !i.disabled) {
|
|
105
|
+
const l = i.shadowRoot?.querySelector(".radio-input");
|
|
78
106
|
if (l) {
|
|
79
|
-
l.focus(),
|
|
80
|
-
const
|
|
107
|
+
l.focus(), i.checked = !0, i.uncheckOtherRadiosInGroup();
|
|
108
|
+
const g = new CustomEvent(
|
|
81
109
|
"change",
|
|
82
110
|
{
|
|
83
111
|
detail: {
|
|
84
112
|
checked: !0,
|
|
85
|
-
value:
|
|
86
|
-
name:
|
|
113
|
+
value: i.value,
|
|
114
|
+
name: i.name
|
|
87
115
|
},
|
|
88
116
|
bubbles: !0,
|
|
89
117
|
composed: !0
|
|
90
118
|
}
|
|
91
119
|
);
|
|
92
|
-
|
|
120
|
+
i.dispatchEvent(g), i.onChange && i.onChange(g);
|
|
93
121
|
}
|
|
94
122
|
}
|
|
95
123
|
}
|
|
96
124
|
getRadiosInGroup() {
|
|
97
125
|
if (!this.name) return [];
|
|
98
|
-
let
|
|
99
|
-
for (;
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
|
|
126
|
+
let e = this.getRootNode();
|
|
127
|
+
for (; e && "host" in e; ) {
|
|
128
|
+
const r = e.host?.getRootNode();
|
|
129
|
+
if (r && r !== e)
|
|
130
|
+
e = r;
|
|
103
131
|
else
|
|
104
132
|
break;
|
|
105
133
|
}
|
|
106
|
-
const
|
|
107
|
-
return Array.from(
|
|
134
|
+
const t = (e instanceof Document ? e : document).querySelectorAll(`ag-radio[name="${this.name}"]`);
|
|
135
|
+
return Array.from(t).filter((r) => r instanceof n && !r.disabled);
|
|
108
136
|
}
|
|
109
|
-
handleChange(
|
|
137
|
+
handleChange(e) {
|
|
110
138
|
if (this.disabled) {
|
|
111
|
-
|
|
139
|
+
e.preventDefault();
|
|
112
140
|
return;
|
|
113
141
|
}
|
|
114
|
-
const
|
|
115
|
-
this.checked =
|
|
116
|
-
const
|
|
142
|
+
const a = e.target, t = this.checked;
|
|
143
|
+
this.checked = a.checked, this._syncFormValue(), this._syncValidity(), this._syncStates(), this.checked && !t && this.name && this.uncheckOtherRadiosInGroup();
|
|
144
|
+
const r = new CustomEvent(
|
|
117
145
|
"change",
|
|
118
146
|
{
|
|
119
147
|
detail: {
|
|
@@ -125,19 +153,19 @@ const t = (n = class extends m(p) {
|
|
|
125
153
|
composed: !0
|
|
126
154
|
}
|
|
127
155
|
);
|
|
128
|
-
this.dispatchEvent(
|
|
156
|
+
this.dispatchEvent(r), this.onChange && this.onChange(r);
|
|
129
157
|
}
|
|
130
158
|
uncheckOtherRadiosInGroup() {
|
|
131
|
-
let
|
|
132
|
-
for (;
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
|
|
159
|
+
let e = this.getRootNode();
|
|
160
|
+
for (; e && "host" in e; ) {
|
|
161
|
+
const r = e.host?.getRootNode();
|
|
162
|
+
if (r && r !== e)
|
|
163
|
+
e = r;
|
|
136
164
|
else
|
|
137
165
|
break;
|
|
138
166
|
}
|
|
139
|
-
(
|
|
140
|
-
|
|
167
|
+
(e instanceof Document ? e : document).querySelectorAll(`ag-radio[name="${this.name}"]`).forEach((r) => {
|
|
168
|
+
r !== this && r instanceof n && (r.checked = !1, r._syncValidity(), r._syncStates());
|
|
141
169
|
});
|
|
142
170
|
}
|
|
143
171
|
/**
|
|
@@ -199,18 +227,18 @@ const t = (n = class extends m(p) {
|
|
|
199
227
|
});
|
|
200
228
|
}
|
|
201
229
|
render() {
|
|
202
|
-
const
|
|
230
|
+
const e = `
|
|
203
231
|
radio-wrapper
|
|
204
232
|
${this.labelPosition === "start" ? "radio-wrapper--label-start" : ""}
|
|
205
|
-
`,
|
|
233
|
+
`, a = `
|
|
206
234
|
radio-indicator
|
|
207
235
|
radio-indicator--${this.size}
|
|
208
236
|
radio-indicator--${this.theme}
|
|
209
|
-
`,
|
|
237
|
+
`, t = `
|
|
210
238
|
radio-label
|
|
211
239
|
radio-label--${this.size}
|
|
212
|
-
`,
|
|
213
|
-
<label class=${
|
|
240
|
+
`, r = this._getAriaDescribedBy(), i = h`
|
|
241
|
+
<label class=${e.trim()} part="ag-radio-wrapper">
|
|
214
242
|
<input
|
|
215
243
|
type="radio"
|
|
216
244
|
id="${this._ids.inputId}"
|
|
@@ -223,14 +251,14 @@ const t = (n = class extends m(p) {
|
|
|
223
251
|
?required=${this.required}
|
|
224
252
|
aria-required="${this.required ? "true" : "false"}"
|
|
225
253
|
aria-invalid="${this.invalid ? "true" : "false"}"
|
|
226
|
-
aria-describedby="${
|
|
254
|
+
aria-describedby="${r || c}"
|
|
227
255
|
@click=${this.handleClick}
|
|
228
256
|
@change=${this.handleChange}
|
|
229
257
|
@keydown=${this.handleKeyDown}
|
|
230
258
|
aria-checked=${this.checked ? "true" : "false"}
|
|
231
259
|
/>
|
|
232
|
-
<span class=${
|
|
233
|
-
<span class=${
|
|
260
|
+
<span class=${a.trim()} part="ag-radio-indicator"></span>
|
|
261
|
+
<span class=${t.trim()} part="ag-radio-label">
|
|
234
262
|
${this.labelText ? this.labelText : h`<slot></slot>`}
|
|
235
263
|
</span>
|
|
236
264
|
</label>
|
|
@@ -238,14 +266,14 @@ const t = (n = class extends m(p) {
|
|
|
238
266
|
return this.label || this.helpText || this.errorMessage ? h`
|
|
239
267
|
<div class="ag-radio-wrapper-with-external">
|
|
240
268
|
${this._renderExternalLabel()}
|
|
241
|
-
${
|
|
269
|
+
${i}
|
|
242
270
|
${this._renderHelper()}
|
|
243
271
|
${this._renderError()}
|
|
244
272
|
</div>
|
|
245
|
-
` :
|
|
273
|
+
` : i;
|
|
246
274
|
}
|
|
247
275
|
}, n.styles = [
|
|
248
|
-
|
|
276
|
+
f,
|
|
249
277
|
b`
|
|
250
278
|
:host {
|
|
251
279
|
display: inline-block;
|
|
@@ -432,55 +460,55 @@ const t = (n = class extends m(p) {
|
|
|
432
460
|
}
|
|
433
461
|
`
|
|
434
462
|
], n);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
],
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
],
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
],
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
],
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
],
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
],
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
],
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
],
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
],
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
],
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
],
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
],
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
],
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
],
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
],
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
],
|
|
483
|
-
let
|
|
463
|
+
d([
|
|
464
|
+
s({ type: String, reflect: !0 })
|
|
465
|
+
], o.prototype, "value");
|
|
466
|
+
d([
|
|
467
|
+
s({ type: Boolean, reflect: !0 })
|
|
468
|
+
], o.prototype, "checked");
|
|
469
|
+
d([
|
|
470
|
+
s({ type: Boolean, reflect: !0 })
|
|
471
|
+
], o.prototype, "disabled");
|
|
472
|
+
d([
|
|
473
|
+
s({ type: String })
|
|
474
|
+
], o.prototype, "size");
|
|
475
|
+
d([
|
|
476
|
+
s({ type: String })
|
|
477
|
+
], o.prototype, "theme");
|
|
478
|
+
d([
|
|
479
|
+
s({ type: String })
|
|
480
|
+
], o.prototype, "labelText");
|
|
481
|
+
d([
|
|
482
|
+
s({ type: String })
|
|
483
|
+
], o.prototype, "labelPosition");
|
|
484
|
+
d([
|
|
485
|
+
s({ type: String })
|
|
486
|
+
], o.prototype, "label");
|
|
487
|
+
d([
|
|
488
|
+
s({ type: Boolean, attribute: "label-hidden" })
|
|
489
|
+
], o.prototype, "labelHidden");
|
|
490
|
+
d([
|
|
491
|
+
s({ type: Boolean, attribute: "no-label" })
|
|
492
|
+
], o.prototype, "noLabel");
|
|
493
|
+
d([
|
|
494
|
+
s({ type: Boolean, reflect: !0 })
|
|
495
|
+
], o.prototype, "required");
|
|
496
|
+
d([
|
|
497
|
+
s({ type: Boolean, reflect: !0 })
|
|
498
|
+
], o.prototype, "invalid");
|
|
499
|
+
d([
|
|
500
|
+
s({ type: String, attribute: "error-message" })
|
|
501
|
+
], o.prototype, "errorMessage");
|
|
502
|
+
d([
|
|
503
|
+
s({ type: String, attribute: "help-text" })
|
|
504
|
+
], o.prototype, "helpText");
|
|
505
|
+
d([
|
|
506
|
+
s({ attribute: !1 })
|
|
507
|
+
], o.prototype, "onClick");
|
|
508
|
+
d([
|
|
509
|
+
s({ attribute: !1 })
|
|
510
|
+
], o.prototype, "onChange");
|
|
511
|
+
let C = o;
|
|
484
512
|
export {
|
|
485
|
-
|
|
513
|
+
C as AgRadio
|
|
486
514
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createFormControlIds,
|
|
6
6
|
buildAriaDescribedBy,
|
|
7
7
|
} from '../../../shared/form-control-utils';
|
|
8
|
-
import { FaceMixin
|
|
8
|
+
import { FaceMixin } from '../../../shared/face-mixin';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
export type RadioSize = 'small' | 'medium' | 'large';
|
|
@@ -356,12 +356,46 @@ export class AgRadio extends FaceMixin(LitElement) implements RadioProps {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
359
|
+
* Returns true if any ag-radio in this named group is checked.
|
|
360
|
+
* Uses the same DOM-traversal logic as uncheckOtherRadiosInGroup so it
|
|
361
|
+
* works whether the radios are in the document or nested inside a shadow root.
|
|
362
|
+
*/
|
|
363
|
+
private _isGroupChecked(): boolean {
|
|
364
|
+
if (this.checked) return true;
|
|
365
|
+
let root: Node = this.getRootNode();
|
|
366
|
+
while (root && 'host' in root) {
|
|
367
|
+
const parent = (root as ShadowRoot).host?.getRootNode();
|
|
368
|
+
if (parent && parent !== root) {
|
|
369
|
+
root = parent;
|
|
370
|
+
} else {
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const doc = root instanceof Document ? root : document;
|
|
375
|
+
return Array.from(doc.querySelectorAll(`ag-radio[name="${this.name}"]`)).some(
|
|
376
|
+
(el) => (el as AgRadio).checked
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Sync validity to ElementInternals.
|
|
382
|
+
*
|
|
383
|
+
* Shadow DOM isolation prevents the inner <input type="radio"> from seeing
|
|
384
|
+
* sibling ag-radio elements in separate shadow trees, so native delegation
|
|
385
|
+
* would report each unchecked required radio as invalid individually.
|
|
386
|
+
* Instead we query the DOM directly: a required radio group is valid when
|
|
387
|
+
* ANY radio with the same name is checked.
|
|
362
388
|
*/
|
|
363
389
|
private _syncValidity(): void {
|
|
364
|
-
|
|
390
|
+
if (!this.required) {
|
|
391
|
+
this._internals.setValidity({});
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (this._isGroupChecked()) {
|
|
395
|
+
this._internals.setValidity({});
|
|
396
|
+
} else {
|
|
397
|
+
this._internals.setValidity({ valueMissing: true }, 'Please select one of these options.');
|
|
398
|
+
}
|
|
365
399
|
}
|
|
366
400
|
|
|
367
401
|
/**
|
|
@@ -571,6 +605,11 @@ export class AgRadio extends FaceMixin(LitElement) implements RadioProps {
|
|
|
571
605
|
allRadios.forEach((radio) => {
|
|
572
606
|
if (radio !== this && radio instanceof AgRadio) {
|
|
573
607
|
radio.checked = false;
|
|
608
|
+
// If checked didn't actually change (was already false), Lit's updated() won't
|
|
609
|
+
// fire on the sibling, so _syncValidity() wouldn't be called. Force it so
|
|
610
|
+
// unchecked siblings correctly reflect the group's new validity state.
|
|
611
|
+
radio._syncValidity();
|
|
612
|
+
radio._syncStates();
|
|
574
613
|
}
|
|
575
614
|
});
|
|
576
615
|
}
|