diff --git a/packages/radio-group/src/LionRadioGroup.js b/packages/radio-group/src/LionRadioGroup.js index 418151bcb..4f861319c 100644 --- a/packages/radio-group/src/LionRadioGroup.js +++ b/packages/radio-group/src/LionRadioGroup.js @@ -83,7 +83,11 @@ export class LionRadioGroup extends LionFieldset { return filtered.length > 0 ? filtered[0] : undefined; } - _setCheckedRadioElement(value, check) { + async _setCheckedRadioElement(value, check) { + if (!this.__readyForRegistration) { + await this.registrationReady; + } + for (let i = 0; i < this.formElementsArray.length; i += 1) { if (check(this.formElementsArray[i], value)) { this.formElementsArray[i].checked = true; diff --git a/packages/radio-group/test/lion-radio-group.test.js b/packages/radio-group/test/lion-radio-group.test.js index da6d6392d..cd55e1aa5 100644 --- a/packages/radio-group/test/lion-radio-group.test.js +++ b/packages/radio-group/test/lion-radio-group.test.js @@ -21,6 +21,24 @@ describe('', () => { expect(el.checkedValue).to.equal('alien'); }); + it('can set initial checkedValue on creation', async () => { + const checkedValue = 'alien'; + const el = await fixture(html` + + + + + + `); + + await nextFrame(); + await el.registrationReady; + await el.updateComplete; + + expect(el.checkedValue).to.equal('alien'); + expect(el.formElementsArray[2].checked).to.be.true; + }); + it('can handle complex data via choiceValue', async () => { const date = new Date(2018, 11, 24, 10, 33, 30, 0);