Skip to content

Commit 60335b3

Browse files
committed
bugfix: wait for the radio elements to be added to the dom before updating their checked state
1 parent 04df44c commit 60335b3

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/uui-radio/lib/uui-radio-group.element.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,7 @@ export class UUIRadioGroupElement extends FormControlMixin(LitElement) {
5959
if (newValue === null || newValue === '') {
6060
this._makeFirstEnabledFocusable();
6161
}
62-
this._radioElements.forEach((el, index) => {
63-
if (el.value === newValue) {
64-
el.checked = true;
65-
this._selected = index;
66-
} else {
67-
el.checked = false;
68-
}
69-
});
62+
this._updateRadioElementsCheckedState(newValue);
7063
}
7164

7265
private _selected: number | null = null;
@@ -75,6 +68,11 @@ export class UUIRadioGroupElement extends FormControlMixin(LitElement) {
7568
super();
7669
this.addEventListener('keydown', this._onKeydown);
7770
this.addEventListener('keypress', this._onKeypress);
71+
72+
// Wait for the radio elements to be added to the dom before updating the checked state.
73+
this.updateComplete.then(() => {
74+
this._updateRadioElementsCheckedState(this.value);
75+
});
7876
}
7977

8078
connectedCallback() {
@@ -112,6 +110,19 @@ export class UUIRadioGroupElement extends FormControlMixin(LitElement) {
112110
this._radioElements?.forEach(el => (el.name = name));
113111
}
114112

113+
private _updateRadioElementsCheckedState(
114+
newValue: FormData | FormDataEntryValue
115+
) {
116+
this._radioElements.forEach((el, index) => {
117+
if (el.value === newValue) {
118+
el.checked = true;
119+
this._selected = index;
120+
} else {
121+
el.checked = false;
122+
}
123+
});
124+
}
125+
115126
private _setDisableOnRadios(value: boolean) {
116127
this._radioElements?.forEach(el => (el.disabled = value));
117128
}

0 commit comments

Comments
 (0)