fix(input-stepper): fires user-input-changed only on increment/decrement

This commit is contained in:
qa46hx 2021-07-05 11:24:42 +02:00
parent 3b388c1d0d
commit 93035755ed
3 changed files with 38 additions and 6 deletions

View file

@ -2,4 +2,5 @@
'@lion/input-stepper': patch
---
fixed the button toggling so it is always toggled if relevant values change
- fixed the button toggling so it is always toggled if relevant values change
- fires user-input-changed only on increment/decrement

View file

@ -171,11 +171,6 @@ export class LionInputStepper extends LionInput {
decrementButton[disableDecrementor ? 'setAttribute' : 'removeAttribute']('disabled', 'true');
incrementButton[disableIncrementor ? 'setAttribute' : 'removeAttribute']('disabled', 'true');
this.setAttribute('aria-valuenow', `${this.currentValue}`);
this.dispatchEvent(
new CustomEvent('user-input-changed', {
bubbles: true,
}),
);
}
/**
@ -202,6 +197,7 @@ export class LionInputStepper extends LionInput {
if (newValue <= max || max === Infinity) {
this.value = `${newValue}`;
this.__toggleSpinnerButtonsState();
this._proxyInputEvent();
}
}
@ -215,6 +211,7 @@ export class LionInputStepper extends LionInput {
if (newValue >= min || min === Infinity) {
this.value = `${newValue}`;
this.__toggleSpinnerButtonsState();
this._proxyInputEvent();
}
}

View file

@ -37,6 +37,40 @@ describe('<lion-input-stepper>', () => {
expect(el.value).to.equal('-1');
});
it('fires one "user-input-changed" event on + button click', async () => {
let counter = 0;
const el = await fixture(html`
<lion-input-stepper
name="year"
label="Years"
@user-input-changed="${() => {
counter += 1;
}}"
>
</lion-input-stepper>
`);
const incrementButton = el.querySelector('[slot=suffix]');
incrementButton?.dispatchEvent(new Event('click'));
expect(counter).to.equal(1);
});
it('fires one "user-input-changed" event on - button click', async () => {
let counter = 0;
const el = await fixture(html`
<lion-input-stepper
name="year"
label="Years"
@user-input-changed="${() => {
counter += 1;
}}"
>
</lion-input-stepper>
`);
const decrementButton = el.querySelector('[slot=prefix]');
decrementButton?.dispatchEvent(new Event('click'));
expect(counter).to.equal(1);
});
it('should update min and max attributes when min and max property change', async () => {
const el = await fixture(inputStepperWithAttrs);
el.min = 100;