Merge pull request #332 from mblankenstein/fix/radioButtonGroupValueZeroOrEmpty

fix(radio-group): change check of value to only null or undefined
This commit is contained in:
Joren Broekema 2019-10-25 07:06:45 -07:00 committed by GitHub
commit 80cdac0130
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -94,7 +94,7 @@ export class LionRadioGroup extends LionFieldset {
__triggerCheckedValueChanged() {
const value = this.checkedValue;
if (value && value !== this.__previousCheckedValue) {
if (value != null && value !== this.__previousCheckedValue) {
this.dispatchEvent(
new CustomEvent('checked-value-changed', { bubbles: true, composed: true }),
);

View file

@ -36,6 +36,20 @@ describe('<lion-radio-group>', () => {
expect(el.checkedValue).to.deep.equal({ some: 'data' });
});
it('can handle 0 and empty string as valid values ', async () => {
const el = await fixture(html`
<lion-radio-group>
<lion-radio name="data[]" .choiceValue=${0} .choiceChecked=${true}></lion-radio>
<lion-radio name="data[]" .choiceValue=${''}></lion-radio>
</lion-radio-group>
`);
await nextFrame();
expect(el.checkedValue).to.equal(0);
el.formElementsArray[1].choiceChecked = true;
expect(el.checkedValue).to.equal('');
});
it('still has a full modelValue ', async () => {
const el = await fixture(html`
<lion-radio-group>