fix(lion-radio-group): wait for registration before setting values (#421)
This commit is contained in:
parent
aa7ff4c37e
commit
4dbd73795f
2 changed files with 23 additions and 1 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue