fix(lion-combobox): The event emitted during clear has stale value (#2104)

This commit is contained in:
Guilherme Amorim 2023-10-18 17:00:30 +02:00 committed by GitHub
parent 83eefe4958
commit 7235a4f703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': minor
---
Fix: Event emited when clearing a combobox sends stale value

View file

@ -1185,8 +1185,8 @@ export class LionCombobox extends LocalizeMixin(OverlayMixin(LionListbox)) {
} }
clear() { clear() {
super.clear();
this.value = ''; this.value = '';
super.clear();
this.__shouldAutocompleteNextUpdate = true; this.__shouldAutocompleteNextUpdate = true;
} }
} }

View file

@ -453,6 +453,32 @@ describe('lion-combobox', () => {
expect(el2._inputNode.value).to.equal(''); expect(el2._inputNode.value).to.equal('');
}); });
it('correctly emits event with an empty value when clear() is called', async () => {
const el = /** @type {LionCombobox} */ (
await fixture(
html`<lion-combobox>
<lion-option .choiceValue=${'red'}>Red</lion-option>
<lion-option .choiceValue=${'green'}>Green</lion-option>
<lion-option .choiceValue=${'blue'}>Blue</lion-option>
</lion-combobox>`,
)
);
el.modelValue = 'red';
await el.updateComplete;
el.addEventListener('model-value-changed', ({ target }) => {
expect(target).to.not.be.null;
const { modelValue, value } = /** @type {LionCombobox} */ (target);
expect(value).to.equal('');
expect(modelValue).to.equal('');
});
el.clear();
await el.updateComplete;
});
it('updates option list after clear()', async () => { it('updates option list after clear()', async () => {
const el = /** @type {LionCombobox} */ ( const el = /** @type {LionCombobox} */ (
await fixture(html` await fixture(html`