@@ -54,18 +54,6 @@ export class RadioGroup<T = any> extends FormControlMixin(LitElement) {
54
54
/** The initial state when the form was associated with the radio group. Used to reset the group. */
55
55
#initialState?: T ;
56
56
57
- /**
58
- * Stores the initial value of the radio group when it is first rendered.
59
- * Used to determine if the value has changed since initialization and to manage event emission, avoiding unnecessary events on the first render.
60
- */
61
- #initialValue?: T ;
62
-
63
- /**
64
- * Indicates whether the component is rendering for the first time.
65
- * Used to track the initial render and preventing unnecessary event emission.
66
- */
67
- #isInitialRender = true ;
68
-
69
57
/** When an option is checked, update the state. */
70
58
#observer = new MutationObserver ( mutations => {
71
59
const { target } = mutations . find ( m => m . attributeName === 'checked' && m . oldValue === null ) || { } ;
@@ -189,11 +177,6 @@ export class RadioGroup<T = any> extends FormControlMixin(LitElement) {
189
177
}
190
178
191
179
if ( changes . has ( 'value' ) ) {
192
- if ( this . #isInitialRender) {
193
- this . #initialValue = this . value ;
194
- this . #isInitialRender = false ;
195
- }
196
-
197
180
this . #observer. disconnect ( ) ;
198
181
this . radios ?. forEach ( radio => ( radio . checked = radio . value === this . value ) ) ;
199
182
this . #observer. observe ( this , OBSERVER_OPTIONS ) ;
@@ -223,10 +206,12 @@ export class RadioGroup<T = any> extends FormControlMixin(LitElement) {
223
206
this . updateState ( { touched : true } ) ;
224
207
}
225
208
226
- #onSlotchange( ) : void {
209
+ async #onSlotchange( ) : Promise < void > {
227
210
this . #rovingTabindexController. clearElementCache ( ) ;
228
211
229
- this . radios ?. forEach ( radio => {
212
+ this . #observer. disconnect ( ) ;
213
+
214
+ for ( const radio of this . radios ?? [ ] ) {
230
215
radio . checked = radio . value === this . value ;
231
216
232
217
if ( typeof this . disabled === 'boolean' ) {
@@ -236,22 +221,24 @@ export class RadioGroup<T = any> extends FormControlMixin(LitElement) {
236
221
if ( this . size ) {
237
222
radio . size = this . size ;
238
223
}
239
- } ) ;
224
+
225
+ // Wait for the `<sl-radio>` to stabilize, otherwise we'll trigger the observer
226
+ await radio . updateComplete ;
227
+ }
228
+
229
+ this . #observer. observe ( this , OBSERVER_OPTIONS ) ;
240
230
}
241
231
242
232
#setSelectedOption( option ?: Radio < T > , emitEvent = true ) : void {
243
233
this . radios ?. forEach ( radio => ( radio . checked = radio . value === option ?. value ) ) ;
244
234
this . value = option ?. value ;
245
235
246
236
if ( emitEvent ) {
247
- if ( ! this . #initialValue) {
248
- this . changeEvent . emit ( this . value ) ;
249
- }
237
+ this . changeEvent . emit ( this . value ) ;
250
238
this . updateState ( { dirty : true } ) ;
251
239
}
252
240
253
241
this . #updateValueAndValidity( ) ;
254
- this . #initialValue = undefined ;
255
242
}
256
243
257
244
#updateValueAndValidity( ) : void {
0 commit comments