From aa8ad0e6b0944027ad304feb712d0681111dc9c9 Mon Sep 17 00:00:00 2001 From: qa46hx Date: Mon, 23 Nov 2020 14:02:17 +0100 Subject: [PATCH] fix(radio-group): reset also if selected value is behind initial value --- .changeset/polite-grapes-attack.md | 9 ++++++++ packages/radio-group/src/LionRadioGroup.js | 22 +++++++++++++++++++ .../radio-group/test/lion-radio-group.test.js | 1 - 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .changeset/polite-grapes-attack.md diff --git a/.changeset/polite-grapes-attack.md b/.changeset/polite-grapes-attack.md new file mode 100644 index 000000000..1ab75992b --- /dev/null +++ b/.changeset/polite-grapes-attack.md @@ -0,0 +1,9 @@ +--- +'@lion/checkbox-group': patch +'@lion/form-core': patch +'@lion/radio-group': patch +--- + +- (RadioGroup) fix reset bug when selected value was behind inital value +- Add ChoiceInputMixin test suite +- Make use of ChoiceGroupMixin test suite diff --git a/packages/radio-group/src/LionRadioGroup.js b/packages/radio-group/src/LionRadioGroup.js index db61cbd14..6b77f83a3 100644 --- a/packages/radio-group/src/LionRadioGroup.js +++ b/packages/radio-group/src/LionRadioGroup.js @@ -10,4 +10,26 @@ export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) super.connectedCallback(); this.setAttribute('role', 'radiogroup'); } + + /** + * @override FormGroupMixin, during a reset if the current checked value is behind + * the initial checked value, they both got unchecked + */ + resetGroup() { + let initValue; + this.formElements.forEach(child => { + if (typeof child.resetGroup === 'function') { + child.resetGroup(); + } else if (typeof child.reset === 'function') { + child.reset(); + // If the value was initially checked save this + if (child.checked) { + initValue = child.value; + } + } + }); + this.modelValue = initValue; + + this.resetInteractionState(); + } } diff --git a/packages/radio-group/test/lion-radio-group.test.js b/packages/radio-group/test/lion-radio-group.test.js index 084b46943..37846dc00 100644 --- a/packages/radio-group/test/lion-radio-group.test.js +++ b/packages/radio-group/test/lion-radio-group.test.js @@ -1,5 +1,4 @@ import { expect, fixture as _fixture, html } from '@open-wc/testing'; - import '../lion-radio-group.js'; import '../lion-radio.js';