Fix(lion-radio-group): Resetting a group containing options with formatters (#2101)

* fix(lion-radio-group): Resetting a group containing options with formatters doesn't check the default value

* refactor: update test name
This commit is contained in:
Guilherme Amorim 2023-10-18 17:10:26 +02:00 committed by GitHub
parent 7235a4f703
commit e923ba40a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': minor
---
fix: Resetting a radio-group containing options with formatters doesn't check the default value

View file

@ -23,7 +23,7 @@ export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement))
child.reset(); child.reset();
// If the value was initially checked save this // If the value was initially checked save this
if (child.checked) { if (child.checked) {
initValue = child.value; initValue = child.choiceValue;
} }
} }
}); });

View file

@ -49,6 +49,35 @@ describe('<lion-radio-group>', () => {
await el.updateComplete; await el.updateComplete;
expect(el.modelValue).to.deep.equal('female'); expect(el.modelValue).to.deep.equal('female');
}); });
it('restores default values if changes were made to a group containing options with formatters', async () => {
const formatter = /** @type {(modelValue: { value: string}) => string} */ modelValue =>
modelValue.value.charAt(0);
const el = await fixture(html`
<lion-radio-group name="gender" label="Gender">
<lion-radio label="Male" .formatter=${formatter} .choiceValue=${'male'}></lion-radio>
<lion-radio
label="Female"
.formatter=${formatter}
.modelValue=${{ value: 'female', checked: true }}
></lion-radio>
<lion-radio label="Other" .formatter=${formatter} .choiceValue=${'other'}></lion-radio>
</lion-radio-group>
`);
el.formElements[0].checked = true;
expect(el.modelValue).to.deep.equal('male');
el.resetGroup();
expect(el.modelValue).to.deep.equal('female');
el.formElements[2].checked = true;
expect(el.modelValue).to.deep.equal('other');
el.resetGroup();
await el.formElements[1].updateComplete;
await el.updateComplete;
expect(el.modelValue).to.deep.equal('female');
});
}); });
it('should have role = radiogroup', async () => { it('should have role = radiogroup', async () => {