fix(form-core): override clear() so modelValue doesn't get erased
This commit is contained in:
parent
ba72b32b00
commit
02145a0644
3 changed files with 21 additions and 1 deletions
5
.changeset/tough-kiwis-lay.md
Normal file
5
.changeset/tough-kiwis-lay.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/form-core': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
for ChoiceInputs override clear() so modelValue doesn't get erased
|
||||||
|
|
@ -238,6 +238,14 @@ const ChoiceInputMixinImplementation = superclass =>
|
||||||
return modelValue && modelValue.value !== undefined ? modelValue.value : modelValue;
|
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.
|
* Used for required validator.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { html } from '@lion/core';
|
import { html } from '@lion/core';
|
||||||
import { LionInput } from '@lion/input';
|
|
||||||
import { Required } from '@lion/form-core';
|
import { Required } from '@lion/form-core';
|
||||||
|
import { LionInput } from '@lion/input';
|
||||||
import { expect, fixture } from '@open-wc/testing';
|
import { expect, fixture } from '@open-wc/testing';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { ChoiceInputMixin } from '../../src/choice-group/ChoiceInputMixin.js';
|
import { ChoiceInputMixin } from '../../src/choice-group/ChoiceInputMixin.js';
|
||||||
|
|
@ -243,6 +243,13 @@ describe('ChoiceInputMixin', () => {
|
||||||
`));
|
`));
|
||||||
expect(elementWithValue.formattedValue).to.equal('foo');
|
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', () => {
|
describe('Interaction states', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue