fix(switch): fire model-value-changed with isTriggeredByUser: true
This commit is contained in:
parent
fce7f3b330
commit
e297c2e1db
3 changed files with 30 additions and 0 deletions
5
.changeset/dirty-ducks-juggle.md
Normal file
5
.changeset/dirty-ducks-juggle.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/switch': patch
|
||||
---
|
||||
|
||||
Fire model-value-changed event with isTriggeredByUser: true when clicking the switch-button.
|
||||
|
|
@ -122,7 +122,9 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
|
|||
|
||||
/** @private */
|
||||
__handleButtonSwitchCheckedChanged() {
|
||||
this._isHandlingUserInput = true;
|
||||
this.checked = this._inputNode.checked;
|
||||
this._isHandlingUserInput = false;
|
||||
}
|
||||
|
||||
/** @protected */
|
||||
|
|
|
|||
|
|
@ -69,6 +69,29 @@ describe('lion-switch', () => {
|
|||
expect(document.activeElement).to.not.equal(_inputNode);
|
||||
});
|
||||
|
||||
it('clicking the switch or the label should fire the model-value-changed event with isTriggeredByUser: true', async () => {
|
||||
let isTriggeredByUser = false;
|
||||
|
||||
/** @param {CustomEvent} ev */
|
||||
const modelValueChanged = ev => {
|
||||
isTriggeredByUser = ev.detail.isTriggeredByUser;
|
||||
};
|
||||
|
||||
const el = await fixture(
|
||||
html`<lion-switch
|
||||
@model-value-changed=${modelValueChanged}
|
||||
label="Enable Setting"
|
||||
></lion-switch>`,
|
||||
);
|
||||
const { _inputNode, _labelNode } = getSwitchMembers(el);
|
||||
|
||||
_inputNode.click();
|
||||
expect(isTriggeredByUser).to.be.true;
|
||||
isTriggeredByUser = false;
|
||||
_labelNode.click();
|
||||
expect(isTriggeredByUser).to.be.true;
|
||||
});
|
||||
|
||||
it('should sync its "disabled" state to child button', async () => {
|
||||
const el = await fixture(html`<lion-switch disabled></lion-switch>`);
|
||||
const { _inputNode } = getSwitchMembers(el);
|
||||
|
|
|
|||
Loading…
Reference in a new issue