From e923ba40a33f05d0f6dc72a732279b8afbd67b73 Mon Sep 17 00:00:00 2001 From: Guilherme Amorim Date: Wed, 18 Oct 2023 17:10:26 +0200 Subject: [PATCH] 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 --- .changeset/forty-books-peel.md | 5 ++++ .../radio-group/src/LionRadioGroup.js | 2 +- .../radio-group/test/lion-radio-group.test.js | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-books-peel.md diff --git a/.changeset/forty-books-peel.md b/.changeset/forty-books-peel.md new file mode 100644 index 0000000000..e914515701 --- /dev/null +++ b/.changeset/forty-books-peel.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': minor +--- + +fix: Resetting a radio-group containing options with formatters doesn't check the default value diff --git a/packages/ui/components/radio-group/src/LionRadioGroup.js b/packages/ui/components/radio-group/src/LionRadioGroup.js index d2c1b75151..cb25f90380 100644 --- a/packages/ui/components/radio-group/src/LionRadioGroup.js +++ b/packages/ui/components/radio-group/src/LionRadioGroup.js @@ -23,7 +23,7 @@ export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) child.reset(); // If the value was initially checked save this if (child.checked) { - initValue = child.value; + initValue = child.choiceValue; } } }); diff --git a/packages/ui/components/radio-group/test/lion-radio-group.test.js b/packages/ui/components/radio-group/test/lion-radio-group.test.js index d2eb96c6c2..b7812daf95 100644 --- a/packages/ui/components/radio-group/test/lion-radio-group.test.js +++ b/packages/ui/components/radio-group/test/lion-radio-group.test.js @@ -49,6 +49,35 @@ describe('', () => { await el.updateComplete; 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` + + + + + + `); + 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 () => {