fix(form-core): override clear() so modelValue doesn't get erased

This commit is contained in:
qa46hx 2020-09-23 17:11:34 +02:00 committed by Thomas Allmer
parent ba72b32b00
commit 02145a0644
3 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/form-core': patch
---
for ChoiceInputs override clear() so modelValue doesn't get erased

View file

@ -238,6 +238,14 @@ const ChoiceInputMixinImplementation = superclass =>
return modelValue && modelValue.value !== undefined ? modelValue.value : modelValue;
}
/**
* @override
* Overridden from LionField, since the modelValue should not be cleared.
*/
clear() {
this.checked = false;
}
/**
* Used for required validator.
*/

View file

@ -1,6 +1,6 @@
import { html } from '@lion/core';
import { LionInput } from '@lion/input';
import { Required } from '@lion/form-core';
import { LionInput } from '@lion/input';
import { expect, fixture } from '@open-wc/testing';
import sinon from 'sinon';
import { ChoiceInputMixin } from '../../src/choice-group/ChoiceInputMixin.js';
@ -243,6 +243,13 @@ describe('ChoiceInputMixin', () => {
`));
expect(elementWithValue.formattedValue).to.equal('foo');
});
it('can clear the checked state', async () => {
const el = /** @type {ChoiceClass} */ (await fixture(`<choice-input></choice-input>`));
el.modelValue = { value: 'foo', checked: true };
el.clear();
expect(el.modelValue).deep.equal({ value: 'foo', checked: false });
});
});
describe('Interaction states', () => {