fix(radio-group): reset also if selected value is behind initial value
This commit is contained in:
parent
8f1456c8cb
commit
aa8ad0e6b0
3 changed files with 31 additions and 1 deletions
9
.changeset/polite-grapes-attack.md
Normal file
9
.changeset/polite-grapes-attack.md
Normal file
|
|
@ -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
|
||||||
|
|
@ -10,4 +10,26 @@ export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement))
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this.setAttribute('role', 'radiogroup');
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { expect, fixture as _fixture, html } from '@open-wc/testing';
|
import { expect, fixture as _fixture, html } from '@open-wc/testing';
|
||||||
|
|
||||||
import '../lion-radio-group.js';
|
import '../lion-radio-group.js';
|
||||||
import '../lion-radio.js';
|
import '../lion-radio.js';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue