File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -74,22 +74,23 @@ export class SingleSelectionController implements ReactiveController {
74
74
constructor ( private readonly host : SingleSelectionElement ) { }
75
75
76
76
hostConnected ( ) {
77
- this . root = this . host . getRootNode ( ) as ParentNode ;
78
77
this . host . addEventListener ( 'keydown' , this . handleKeyDown ) ;
79
78
this . host . addEventListener ( 'focusin' , this . handleFocusIn ) ;
80
79
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
- }
86
80
87
81
// Update siblings after a microtask to allow other synchronous connected
88
82
// callbacks to settle before triggering additional Lit updates. This avoids
89
83
// stack overflow issues when too many elements are being rendered and
90
84
// connected at the same time.
91
85
queueMicrotask ( ( ) => {
92
86
// 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
+
93
94
this . updateTabIndices ( ) ;
94
95
} ) ;
95
96
}
Original file line number Diff line number Diff line change @@ -368,19 +368,22 @@ describe('<md-radio>', () => {
368
368
// Connecting r1 shouldn't change anything, since it's the only one in the
369
369
// group.
370
370
container . appendChild ( r1 ) ;
371
+ await env . waitForStability ( ) ;
371
372
expect ( r1 . checked ) . toBeTrue ( ) ;
372
373
expect ( r2 . checked ) . toBeTrue ( ) ;
373
374
expect ( r3 . checked ) . toBeFalse ( ) ;
374
375
375
376
// Appending r2 should uncheck r1, because when a new checked radio is
376
377
// connected, it wins (this matches native input behavior).
377
378
container . appendChild ( r2 ) ;
379
+ await env . waitForStability ( ) ;
378
380
expect ( r1 . checked ) . toBeFalse ( ) ;
379
381
expect ( r2 . checked ) . toBeTrue ( ) ;
380
382
expect ( r3 . checked ) . toBeFalse ( ) ;
381
383
382
384
// Appending r3 shouldn't change anything, because it's not checked.
383
385
container . appendChild ( r3 ) ;
386
+ await env . waitForStability ( ) ;
384
387
expect ( r1 . checked ) . toBeFalse ( ) ;
385
388
expect ( r2 . checked ) . toBeTrue ( ) ;
386
389
expect ( r3 . checked ) . toBeFalse ( ) ;
You can’t perform that action at this time.
0 commit comments