Skip to content

Commit 085c799

Browse files
authored
Merge branch 'main' into patch-2
2 parents 8c3ade8 + 834a166 commit 085c799

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

radio/internal/single-selection-controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,23 @@ export class SingleSelectionController implements ReactiveController {
7474
constructor(private readonly host: SingleSelectionElement) {}
7575

7676
hostConnected() {
77-
this.root = this.host.getRootNode() as ParentNode;
7877
this.host.addEventListener('keydown', this.handleKeyDown);
7978
this.host.addEventListener('focusin', this.handleFocusIn);
8079
this.host.addEventListener('focusout', this.handleFocusOut);
81-
if (this.host.checked) {
82-
// Uncheck other siblings when attached if already checked. This mimics
83-
// native <input type="radio"> behavior.
84-
this.uncheckSiblings();
85-
}
8680

8781
// Update siblings after a microtask to allow other synchronous connected
8882
// callbacks to settle before triggering additional Lit updates. This avoids
8983
// stack overflow issues when too many elements are being rendered and
9084
// connected at the same time.
9185
queueMicrotask(() => {
9286
// Update for the newly added host.
87+
this.root = this.host.getRootNode() as ParentNode;
88+
if (this.host.checked) {
89+
// Uncheck other siblings when attached if already checked. This mimics
90+
// native <input type="radio"> behavior.
91+
this.uncheckSiblings();
92+
}
93+
9394
this.updateTabIndices();
9495
});
9596
}

radio/radio_test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,22 @@ describe('<md-radio>', () => {
368368
// Connecting r1 shouldn't change anything, since it's the only one in the
369369
// group.
370370
container.appendChild(r1);
371+
await env.waitForStability();
371372
expect(r1.checked).toBeTrue();
372373
expect(r2.checked).toBeTrue();
373374
expect(r3.checked).toBeFalse();
374375

375376
// Appending r2 should uncheck r1, because when a new checked radio is
376377
// connected, it wins (this matches native input behavior).
377378
container.appendChild(r2);
379+
await env.waitForStability();
378380
expect(r1.checked).toBeFalse();
379381
expect(r2.checked).toBeTrue();
380382
expect(r3.checked).toBeFalse();
381383

382384
// Appending r3 shouldn't change anything, because it's not checked.
383385
container.appendChild(r3);
386+
await env.waitForStability();
384387
expect(r1.checked).toBeFalse();
385388
expect(r2.checked).toBeTrue();
386389
expect(r3.checked).toBeFalse();

0 commit comments

Comments
 (0)