fix: combobox clear function (#1315)

* fix(combobox): clear() method

Co-authored-by: Thijs Louisse <Thijs.Louisse@ing.com>
This commit is contained in:
realfighter92 2021-04-08 16:07:08 +05:30 committed by GitHub
parent 2687e15189
commit 0dc706b6f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/combobox': patch
---
Add clear() function combobox

View file

@ -892,4 +892,9 @@ export class LionCombobox extends OverlayMixin(LionListbox) {
currentValue: this._inputNode.value,
});
}
clear() {
super.clear();
this._inputNode.value = '';
}
}

View file

@ -317,6 +317,36 @@ describe('lion-combobox', () => {
expect(el.modelValue).to.eql([]);
expect(el.formElements[0].checked).to.be.false;
});
it('clears modelValue and textbox value on clear()', async () => {
const el = /** @type {LionCombobox} */ (await fixture(html`
<lion-combobox name="foo" .modelValue="${'Artichoke'}">
<lion-option .choiceValue="${'Artichoke'}">Artichoke</lion-option>
<lion-option .choiceValue="${'Chard'}">Chard</lion-option>
<lion-option .choiceValue="${'Chicory'}">Chicory</lion-option>
<lion-option .choiceValue="${'Victoria Plum'}">Victoria Plum</lion-option>
</lion-combobox>
`));
const { inputNode } = getProtectedMembers(el);
el.clear();
expect(el.modelValue).to.equal('');
expect(inputNode.value).to.equal('');
const el2 = /** @type {LionCombobox} */ (await fixture(html`
<lion-combobox name="foo" multiple-choice .modelValue="${['Artichoke']}">
<lion-option .choiceValue="${'Artichoke'}">Artichoke</lion-option>
<lion-option .choiceValue="${'Chard'}">Chard</lion-option>
<lion-option .choiceValue="${'Chicory'}">Chicory</lion-option>
<lion-option .choiceValue="${'Victoria Plum'}">Victoria Plum</lion-option>
</lion-combobox>
`));
el2.clear();
expect(el2.modelValue).to.eql([]);
expect(inputNode.value).to.equal('');
});
});
describe('Overlay visibility', () => {

View file

@ -443,6 +443,11 @@ const ListboxMixinImplementation = superclass =>
this.resetInteractionState();
}
clear() {
this.setCheckedIndex(-1);
this.resetInteractionState();
}
/**
* @override ChoiceGroupMixin: in the select disabled options are still going to a possible
* value, for example when prefilling or programmatically setting it.