fix(lion-radio-group): wait for registration before setting values (#421)

This commit is contained in:
vrspider 2019-12-11 16:43:27 +01:00 committed by Thijs Louisse
parent aa7ff4c37e
commit 4dbd73795f
2 changed files with 23 additions and 1 deletions

View file

@ -83,7 +83,11 @@ export class LionRadioGroup extends LionFieldset {
return filtered.length > 0 ? filtered[0] : undefined; 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) { for (let i = 0; i < this.formElementsArray.length; i += 1) {
if (check(this.formElementsArray[i], value)) { if (check(this.formElementsArray[i], value)) {
this.formElementsArray[i].checked = true; this.formElementsArray[i].checked = true;

View file

@ -21,6 +21,24 @@ describe('<lion-radio-group>', () => {
expect(el.checkedValue).to.equal('alien'); expect(el.checkedValue).to.equal('alien');
}); });
it('can set initial checkedValue on creation', async () => {
const checkedValue = 'alien';
const el = await fixture(html`
<lion-radio-group .checkedValue="${checkedValue}">
<lion-radio name="gender[]" .choiceValue=${'male'}></lion-radio>
<lion-radio name="gender[]" .choiceValue=${'female'}></lion-radio>
<lion-radio name="gender[]" .choiceValue=${'alien'}></lion-radio>
</lion-radio-group>
`);
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 () => { it('can handle complex data via choiceValue', async () => {
const date = new Date(2018, 11, 24, 10, 33, 30, 0); const date = new Date(2018, 11, 24, 10, 33, 30, 0);